Initial code import
[msb/apigateway.git] / openresty-ext / src / assembly / resources / openresty / nginx / msb-enabled / msb.conf
1 #
2 # Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
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
17 #the maximum allowed size of the client request body,current 10G
18 client_max_body_size 10240m; 
19 client_body_buffer_size 128k;
20         
21 #set conf for proxy pass
22 proxy_connect_timeout 10s;
23 proxy_read_timeout 120s;
24 proxy_send_timeout 120s;
25 proxy_set_header X-Real-IP $remote_addr;
26 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
27 proxy_set_header Host $host:$server_port;
28 proxy_buffers 4 16k;
29
30 #set the nginx_cache parameter
31 proxy_cache_path  temp/proxy_cache  levels=1:2   keys_zone=nginx_cache:100m inactive=1d max_size=1g;
32 proxy_cache_key $host$uri$is_args$args;
33 proxy_cache_revalidate on;
34 proxy_cache_min_uses 3;
35 proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
36 proxy_cache_lock on;
37
38 # Lua settings
39 lua_package_path "$prefix/../lualib/?.lua;$prefix/luaext/?.lua;;";
40 lua_package_cpath "$prefix/../lualib/?.so;;";
41 lua_shared_dict rr_cache 1M;
42 lua_shared_dict rr_locks 100k;
43
44 lua_shared_dict svc_cache 5M;
45 lua_shared_dict locks 200k;
46
47 lua_code_cache on;
48
49 # Basic reverse proxy server processor
50 upstream defaultbackend {
51         server 0.0.0.1;
52         balancer_by_lua_file luaext/loadbalance/balancer.lua;
53         #keepalive 10;
54 }
55
56 server {
57         listen 10080;
58         default_type text/html;
59         
60         # the flag identify whether to check doing internal redirect or not
61         set $websocket_internal_redirect "on";
62         
63         location = /msb {
64                 #try_files $uri @defaulthomepage;
65                 rewrite ^ /iui/microservices/default.html redirect;
66         }
67         
68         location = /iui/microservices {
69                 try_files $uri @addslash;
70         }
71
72         location @addslash {
73                 return 302 $scheme://$http_host$uri/;
74         }
75         
76         location @defaulthomepage {
77                 return 302 $scheme://$http_host/iui/microservices/default.html;
78         }
79         
80         error_page 410 = @commonnotfound;
81         
82         location @commonnotfound {
83                 set $svc_type "custom";
84                 set $svc_name "";
85                 set $svc_url "";
86                 set $backend "defaultbackend";
87                 
88                 #rewrite by the lua file
89                 rewrite_by_lua_file luaext/rewrite/customrewrite.lua;
90                 #log by the lua file
91                 log_by_lua_file luaext/log/logger.lua;
92                 
93                 proxy_pass http://$backend;
94                 proxy_redirect http://$host:$server_port$svc_url http://$host:$server_port$svc_name;  
95         }
96         
97         location @customwebsocket {
98                 set $websocket_internal_redirect "off";
99                 #set header for websocket
100                 proxy_http_version 1.1;
101                 proxy_set_header Upgrade $http_upgrade;
102                 proxy_set_header Connection "Upgrade";
103                 
104                 proxy_set_header X-Real-IP $remote_addr;
105                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
106                 proxy_set_header Host $host:$server_port;
107                 
108                 #rewrite by the lua file
109                 rewrite_by_lua_file luaext/rewrite/customrewrite.lua;
110                 #log by the lua file
111                 log_by_lua_file luaext/log/logger.lua;
112                 
113                 proxy_pass http://$backend;  
114         }
115         
116         location @commonwebsocket {
117                 set $websocket_internal_redirect "off";
118                 #set header for websocket
119                 proxy_http_version 1.1;
120                 proxy_set_header Upgrade $http_upgrade;
121                 proxy_set_header Connection "Upgrade";
122                 
123                 proxy_set_header X-Real-IP $remote_addr;
124                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
125                 proxy_set_header Host $host:$server_port;
126                 
127                 #rewrite by the lua file
128                 rewrite_by_lua_file luaext/rewrite/commonrewrite.lua;
129                 #log by the lua file
130                 log_by_lua_file luaext/log/logger.lua;
131                 
132                 proxy_pass http://$backend;  
133         }
134         
135         location / {
136                 set $svc_type "custom";
137                 set $svc_name "";
138                 set $svc_url "";
139                 set $backend "defaultbackend";
140                 
141                 #rewrite by the lua file
142                 rewrite_by_lua_file luaext/rewrite/customrewrite.lua;
143                 #log by the lua file
144                 log_by_lua_file luaext/log/logger.lua;
145                 
146                 proxy_pass http://$backend;
147                 proxy_redirect http://$host:$server_port$svc_url http://$host:$server_port$svc_name;  
148         }
149
150         location ~ ^/(api|admin|apijson)(/[Vv]\d+(?:\.\d+)*)?/([^/]+)(/[Vv]\d+(?:\.\d+)*)?(.*) {
151                 set $svc_type $1;
152                 set $svc_name $3;
153                 set $svc_version1 $2;
154                 set $svc_version2 $4;
155                 set $req_res $5;
156                 set $backend "defaultbackend";
157                 
158                 #rewrite by the lua file
159                 rewrite_by_lua_file luaext/rewrite/commonrewrite.lua;
160                 #log by the lua file
161                 log_by_lua_file luaext/log/logger.lua;
162                 
163                 proxy_pass http://$backend;
164         }
165         
166         location ~* ^/iui/([^/]+)(.*)\.(png|jpg|jpeg|gif|ico|bmp|woff)$ {
167                 set $svc_type "iui";
168                 set $svc_name $1;
169                 set $req_res $2.$3;
170                 set $backend "defaultbackend";
171                 
172                 #rewrite by the lua file
173                 rewrite_by_lua_file luaext/rewrite/commonrewrite.lua;
174                 #log by the lua file
175                 log_by_lua_file luaext/log/logger.lua;
176                 
177                 proxy_cache nginx_cache;
178                 add_header X-Cache-Status $upstream_cache_status;
179                 proxy_pass http://$backend;
180         }
181         
182         location ~ ^/iui/([^/]+)(.*) {
183                 set $svc_type "iui";
184                 set $svc_name $1;
185                 set $req_res $2;
186                 set $backend "defaultbackend";
187                 
188                 #rewrite by the lua file
189                 rewrite_by_lua_file luaext/rewrite/commonrewrite.lua;
190                 #log by the lua file
191                 log_by_lua_file luaext/log/logger.lua;
192                 
193                 proxy_pass http://$backend;
194         }
195         
196         location ~* \.(?:png|jpg|jpeg|gif|ico|bmp|woff)$ {
197                 set $svc_type "custom";
198                 set $svc_name "";
199                 set $svc_url "";
200                 set $backend "defaultbackend";
201                 
202                 #rewrite by the lua file
203                 rewrite_by_lua_file luaext/rewrite/customrewrite.lua;
204                 #log by the lua file
205                 log_by_lua_file luaext/log/logger.lua;
206                 
207                 proxy_cache nginx_cache;
208                 add_header X-Cache-Status $upstream_cache_status;
209                 proxy_pass http://$backend;
210                 proxy_redirect http://$host:$server_port$svc_url http://$host:$server_port$svc_name;  
211         }
212         
213         location = /favicon.ico {
214                 log_not_found off;
215         }
216         include ../msb-enabled/location-ext/*.conf;
217         include ../msb-enabled/location-ext-mount/*.conf;
218 }