eadf6c04c8f1707194457366d7b7b5a25b5f5041
[msb/apigateway.git] / msb-core / eag-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 8080;
22    default_type text/html;
23    add_header X-Cache-Status $upstream_cache_status;
24    
25         location = / {
26       rewrite ^ /openoui/microservices/index.html redirect;
27    }
28    
29    location = /openoui/microservices {
30       rewrite /openoui/microservices /openoui/microservices/index.html redirect;
31    }
32   
33    location / {
34           set $server "fallback";
35                   set $url "";
36                   set $key "";
37                   
38                   # Lua files
39           rewrite_by_lua_file luaext/customrouter.lua;
40                   access_by_lua_file luaext/execute_auth.lua;
41                   
42                   proxy_pass http://$server;
43    }
44     location ~ ^/api/(.*) {
45                 rewrite ^/api/(.*) /openoapi/$1 last;
46     }
47     location ~ ^/iui/(.*) {
48                 rewrite ^/iui/(.*) /openoui/$1 last;
49         }
50         
51         location ^~ /openoapi/driver_vmware_vcloud/v1 {
52                   set $backend "";
53                   # Lua files
54           access_by_lua_block {
55                         local driver_manager   =  require('plugins.driver_manager')
56                         driver_manager.access()
57                  }
58                  proxy_pass http://$backend;
59     }
60    location ~ ^/openoapi/([^/]+)(/[Vv][^/]*)?(.*) {
61           set $apiname $1;
62                   set $apiversion $2;
63           set $apiserver "fallback";
64                   set $apiurl "";
65
66           # Lua files
67           rewrite_by_lua_file luaext/openoapirouter.lua;
68                   access_by_lua_file luaext/execute_auth.lua;
69                   
70            proxy_pass http://$apiserver;
71    }
72
73    location ~ ^/openoui/([^/]+)(.*) {
74           location ~* ^/iui/([^/]+)(.*)\.(?:png|jpg|jpeg|js|css|html|gif|ico|bmp|woff)$ {
75                   set $iuiname $1;
76                           set $iuiparam $2;
77                   set $iuiserver "fallback";
78                           set $iuiurl "";
79                   
80                           # Lua files
81                                   rewrite_by_lua_file luaext/openouirouter.lua;
82                                   access_by_lua_file luaext/execute_auth.lua;
83
84                                   proxy_cache nginx_cache;
85                                   proxy_cache_key $host$uri$is_args$args;
86                                   proxy_cache_valid 200 304 12h ;
87                                   proxy_cache_valid 301 302 1m ;
88                                   proxy_cache_valid any 1m ;
89                                   expires 12h;
90                                   
91                                   proxy_pass http://$iuiserver;           
92                   }  
93                   set $iuiname $1;
94                   set $iuiparam $2;
95           set $iuiserver "fallback";
96                   set $iuiurl "";
97
98           # Lua files
99           rewrite_by_lua_file luaext/openouirouter.lua;
100                   access_by_lua_file luaext/execute_auth.lua;
101                   
102                   proxy_pass http://$iuiserver;
103    }
104
105    location ~ ^/admin/([^/]+)(/[Vv][^/]*)?(.*) {
106           set $apiname $1;
107               set $apiversion $2;
108           set $apiserver "fallback";
109                   set $adminurl "";
110                   
111                   # Lua files
112           rewrite_by_lua_file luaext/openoadminrouter.lua;
113                   access_by_lua_file luaext/execute_auth.lua;
114                   
115                   proxy_pass http://$apiserver;
116    }
117    
118    location ~ ^/apijson/([^/]+)(/[Vv][^/]*)?(.*) {
119           location ~* ^/apijson/([^/]+)(/[v][^/]*)?(.*)\.(?:png|jpg|jpeg|js|css|html|gif|ico|bmp|woff)$ {
120                   set $apiname $1;
121                           set $apiversion $2;
122                   set $apiserver "fallback";
123                           set $apijsonurl "";             
124                                   
125                           # Lua files
126                                   rewrite_by_lua_file luaext/openoapijsonrouter.lua;
127                                   access_by_lua_file luaext/execute_auth.lua;
128
129                                   proxy_cache nginx_cache;
130                                   proxy_cache_key $host$uri$is_args$args;
131                                   proxy_cache_valid 200 304 12h ;
132                                   proxy_cache_valid 301 302 1m ;
133                                   proxy_cache_valid any 1m ;
134                                   expires 12h;
135                                   
136                                   proxy_pass http://$apiserver;           
137                   }   
138           set $apiname $1;
139               set $apiversion $2;
140           set $apiserver "fallback";
141                   set $apijsonurl "";
142                   
143                   # Lua files
144           rewrite_by_lua_file luaext/openoapijsonrouter.lua;
145                   access_by_lua_file luaext/execute_auth.lua;
146                   
147                   proxy_pass http://$apiserver;
148    }
149
150    location ~* \.(?:png|jpg|jpeg|js|css|html|gif|ico|bmp|woff)$ {
151            set $server "fallback";
152                    set $url "";
153            set $key "";
154                   
155                    # Lua files
156                    rewrite_by_lua_file luaext/customrouter.lua;
157                    access_by_lua_file luaext/execute_auth.lua;
158
159                    proxy_cache nginx_cache;
160                    proxy_cache_key $host$uri$is_args$args;
161                    proxy_cache_valid 200 304 12h ;
162                    proxy_cache_valid 301 302 1m ;
163                    proxy_cache_valid any 1m ;
164                    expires 12h;
165                                   
166                    proxy_pass http://$server;             
167    }
168          
169    location = /favicon.ico {
170         log_not_found off;
171    }
172 }