Divide the MSB source codes into two repos
[msb/apigateway.git] / openresty-ext / src / assembly / resources / openresty / nginx / msb-enabled / location-default / msblocations.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         default_type text/html;
18         
19         # the flag identify whether to check doing internal redirect or not
20         set $websocket_internal_redirect "on";
21         set $http_protocol "http";
22
23         
24         location = /iui/microservices {
25                 try_files $uri @addslash;
26         }
27
28         location @addslash {
29                 return 302 $scheme://$http_host$uri/;
30         }
31         
32         #error_page 410 = @commonnotfound;
33         
34         location @commonnotfound {
35                 set $svc_type "custom";
36                 set $svc_name "";
37                 set $svc_url "";
38                 set $backend "defaultbackend";
39                 
40                 #rewrite by the lua file
41                 rewrite_by_lua_file luaext/rewrite/customrewrite.lua;
42                 access_by_lua_block {
43                         msb.access()
44                 }
45                 header_filter_by_lua_block {
46                         msb.header_filter()
47                 }
48                 #log by the lua file
49                 log_by_lua_file luaext/log/logger.lua;
50                 
51                 proxy_pass $http_protocol://$backend;
52                 proxy_redirect $http_protocol://$host:$server_port$svc_url $http_protocol://$host:$server_port$svc_name;  
53         }
54         
55         location @customwebsocket {
56                 set $websocket_internal_redirect "off";
57                 #set header for websocket
58                 proxy_http_version 1.1;
59                 proxy_set_header Upgrade $http_upgrade;
60                 proxy_set_header Connection "Upgrade";
61                 
62                 proxy_set_header X-Real-IP $remote_addr;
63                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
64                 proxy_set_header Host $host:$server_port;
65                 
66                 #rewrite by the lua file
67                 rewrite_by_lua_file luaext/rewrite/customrewrite.lua;
68                 access_by_lua_block {
69                         msb.access()
70                 }
71                 header_filter_by_lua_block {
72                         msb.header_filter()
73                 }
74                 #log by the lua file
75                 log_by_lua_file luaext/log/logger.lua;
76                 
77                 proxy_pass $http_protocol://$backend;  
78         }
79         
80         location @commonwebsocket {
81                 set $websocket_internal_redirect "off";
82                 #set header for websocket
83                 proxy_http_version 1.1;
84                 proxy_set_header Upgrade $http_upgrade;
85                 proxy_set_header Connection "Upgrade";
86                 
87                 proxy_set_header X-Real-IP $remote_addr;
88                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
89                 proxy_set_header Host $host:$server_port;
90                 
91                 #rewrite by the lua file
92                 rewrite_by_lua_file luaext/rewrite/commonrewrite.lua;
93                 access_by_lua_block {
94                         msb.access()
95                 }
96                 header_filter_by_lua_block {
97                         msb.header_filter()
98                 }
99                 #log by the lua file
100                 log_by_lua_file luaext/log/logger.lua;
101                 
102                 proxy_pass $http_protocol://$backend;  
103         }
104         
105         location / {
106                 set $svc_type "custom";
107                 set $svc_name "";
108                 set $svc_url "";
109                 set $backend "defaultbackend";
110                 
111                 #rewrite by the lua file
112                 rewrite_by_lua_file luaext/rewrite/customrewrite.lua;
113                 access_by_lua_block {
114                         msb.access()
115                 }
116                 header_filter_by_lua_block {
117                         msb.header_filter()
118                 }
119                 #log by the lua file
120                 log_by_lua_file luaext/log/logger.lua;
121                 
122                 proxy_pass $http_protocol://$backend;
123                 proxy_redirect $http_protocol://$host:$server_port$svc_url $http_protocol://$host:$server_port$svc_name;  
124         }
125
126         location ~ ^/(api|admin|apijson)(/[Vv]\d+(?:\.\d+)*)?/([^/]+)(/[Vv]\d+(?:\.\d+)*)?(.*) {
127                 set $svc_type $1;
128                 set $svc_name $3;
129                 set $svc_version1 $2;
130                 set $svc_version2 $4;
131                 set $req_res $5;
132                 set $backend "defaultbackend";
133                 
134                 #rewrite by the lua file
135                 rewrite_by_lua_file luaext/rewrite/commonrewrite.lua;
136                 access_by_lua_block {
137                         msb.access()
138                 }
139                 header_filter_by_lua_block {
140                         msb.header_filter()
141                 }
142                 #log by the lua file
143                 log_by_lua_file luaext/log/logger.lua;
144                 
145                 proxy_pass $http_protocol://$backend;
146         }
147         
148         location ~* ^/iui/([^/]+)(.*)\.(png|jpg|jpeg|gif|ico|bmp|woff)$ {
149                 set $svc_type "iui";
150                 set $svc_name $1;
151                 set $req_res $2.$3;
152                 set $backend "defaultbackend";
153                 
154                 #rewrite by the lua file
155                 rewrite_by_lua_file luaext/rewrite/commonrewrite.lua;
156                 access_by_lua_block {
157                         msb.access()
158                 }
159                 header_filter_by_lua_block {
160                         msb.header_filter()
161                 }
162                 #log by the lua file
163                 log_by_lua_file luaext/log/logger.lua;
164                 
165                 proxy_cache nginx_cache;
166                 add_header X-Cache-Status $upstream_cache_status;
167                 proxy_pass $http_protocol://$backend;
168         }
169         
170         location ~ ^/iui/([^/]+)(.*) {
171                 set $svc_type "iui";
172                 set $svc_name $1;
173                 set $req_res $2;
174                 set $backend "defaultbackend";
175                 
176                 #rewrite by the lua file
177                 rewrite_by_lua_file luaext/rewrite/commonrewrite.lua;
178                 access_by_lua_block {
179                         msb.access()
180                 }
181                 header_filter_by_lua_block {
182                         msb.header_filter()
183                 }
184                 #log by the lua file
185                 log_by_lua_file luaext/log/logger.lua;
186                 
187                 proxy_pass $http_protocol://$backend;
188         }
189         
190         include ../msb-enabled/location-ext/*.conf;
191         include ../msb-enabled/location-ext-mount/*.conf;
192         
193         location ~* \.(?:png|jpg|jpeg|gif|ico|bmp|woff)$ {
194                 set $svc_type "custom";
195                 set $svc_name "";
196                 set $svc_url "";
197                 set $backend "defaultbackend";
198                 
199                 #rewrite by the lua file
200                 rewrite_by_lua_file luaext/rewrite/customrewrite.lua; 
201                 access_by_lua_block {
202                         msb.access()
203                 }
204                 header_filter_by_lua_block {
205                         msb.header_filter()
206                 }
207                 #log by the lua file
208                 log_by_lua_file luaext/log/logger.lua;
209                 
210                 proxy_cache nginx_cache;
211                 add_header X-Cache-Status $upstream_cache_status;
212                 proxy_pass $http_protocol://$backend;
213                 proxy_redirect http://$host:$server_port$svc_url http://$host:$server_port$svc_name;  
214         }
215         
216         location = /favicon.ico {
217                 log_not_found off;
218         }