Issue-id: OCS-9
[msb/apigateway.git] / msb-core / openresty-ext / src / assembly / resources / openresty / nginx / sites-enabled / openomsb.conf
1 #
2 # Copyright 2016 2015-2016 ZTE, Inc. and others. All rights reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 #     Author: Zhaoxing Meng
17 #     email: meng.zhaoxing1@zte.com.cn
18 #
19
20 server {
21    listen 80;
22    default_type text/html;
23    add_header X-Cache-Status $upstream_cache_status;
24         
25    location = /openoui/microservices {
26       rewrite /openoui/microservices /openoui/microservices/index.html redirect;
27    }
28   
29    location / {
30           set $server "fallback";
31                   set $url "";
32                   set $key "";
33                   
34                   # Lua files
35           rewrite_by_lua_file luaext/customrouter.lua;
36                   
37                   proxy_pass http://$server;
38    }
39     location ~ ^/api/(.*) {
40                 rewrite ^/api/(.*) /openoapi/$1 last;
41     }
42     location ~ ^/iui/(.*) {
43                 rewrite ^/iui/(.*) /openoui/$1 last;
44         }
45    location ~ ^/openoapi/([^/]+)(/[Vv][^/]*)?(.*) {
46           set $apiname $1;
47                   set $apiversion $2;
48           set $apiserver "fallback";
49                   set $apiurl "";
50
51           # Lua files
52           rewrite_by_lua_file luaext/openoapirouter.lua;
53                   
54            proxy_pass http://$apiserver;
55    }
56
57    location ~ ^/openoui/([^/]+)(.*) {
58           location ~* ^/iui/([^/]+)(.*)\.(?:png|jpg|jpeg|js|css|html|gif|ico|bmp|woff)$ {
59                   set $iuiname $1;
60                           set $iuiparam $2;
61                   set $iuiserver "fallback";
62                           set $iuiurl "";
63                   
64                           # Lua files
65                                   rewrite_by_lua_file luaext/openouirouter.lua;
66
67                                   proxy_cache nginx_cache;
68                                   proxy_cache_key $host$uri$is_args$args;
69                                   proxy_cache_valid 200 304 12h ;
70                                   proxy_cache_valid 301 302 1m ;
71                                   proxy_cache_valid any 1m ;
72                                   expires 12h;
73                                   
74                                   proxy_pass http://$iuiserver;           
75                   }  
76                   set $iuiname $1;
77                   set $iuiparam $2;
78           set $iuiserver "fallback";
79                   set $iuiurl "";
80
81           # Lua files
82           rewrite_by_lua_file luaext/openouirouter.lua;
83                   
84                   proxy_pass http://$iuiserver;
85    }
86
87    location ~ ^/admin/([^/]+)(/[Vv][^/]*)?(.*) {
88           set $apiname $1;
89               set $apiversion $2;
90           set $apiserver "fallback";
91                   set $adminurl "";
92                   
93                   # Lua files
94           rewrite_by_lua_file luaext/openoadminrouter.lua;
95                   
96                   proxy_pass http://$apiserver;
97    }
98    
99    location ~ ^/apijson/([^/]+)(/[Vv][^/]*)?(.*) {
100           location ~* ^/apijson/([^/]+)(/[v][^/]*)?(.*)\.(?:png|jpg|jpeg|js|css|html|gif|ico|bmp|woff)$ {
101                   set $apiname $1;
102                           set $apiversion $2;
103                   set $apiserver "fallback";
104                           set $apijsonurl "";             
105                                   
106                           # Lua files
107                                   rewrite_by_lua_file luaext/openoapijsonrouter.lua;
108
109                                   proxy_cache nginx_cache;
110                                   proxy_cache_key $host$uri$is_args$args;
111                                   proxy_cache_valid 200 304 12h ;
112                                   proxy_cache_valid 301 302 1m ;
113                                   proxy_cache_valid any 1m ;
114                                   expires 12h;
115                                   
116                                   proxy_pass http://$apiserver;           
117                   }   
118           set $apiname $1;
119               set $apiversion $2;
120           set $apiserver "fallback";
121                   set $apijsonurl "";
122                   
123                   # Lua files
124           rewrite_by_lua_file luaext/openoapijsonrouter.lua;
125                   
126                   proxy_pass http://$apiserver;
127    }
128
129    location ~* \.(?:png|jpg|jpeg|js|css|html|gif|ico|bmp|woff)$ {
130            set $server "fallback";
131                    set $url "";
132            set $key "";
133                   
134                    # Lua files
135                    rewrite_by_lua_file luaext/customrouter.lua;
136
137                    proxy_cache nginx_cache;
138                    proxy_cache_key $host$uri$is_args$args;
139                    proxy_cache_valid 200 304 12h ;
140                    proxy_cache_valid 301 302 1m ;
141                    proxy_cache_valid any 1m ;
142                    expires 12h;
143                                   
144                    proxy_pass http://$server;             
145    }
146          
147    location = /favicon.ico {
148         log_not_found off;
149    }
150 }