Skip to content

Commit 2523248

Browse files
author
孟庆芳
committed
nginx
1 parent fb4c692 commit 2523248

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

17基础设施/nginx.conf

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Nginx多环境配置
2+
3+
```conf
4+
5+
upstream 2879137 {
6+
server 172.18.0.4:31233;
7+
}
8+
9+
upstream 3383230 {
10+
server 172.18.0.4:22399;
11+
}
12+
13+
upstream main-latest {
14+
server 172.18.0.4:27146;
15+
}
16+
17+
18+
server {
19+
listen 80;
20+
server_name ~^(?<subdomain>.+)\.test\.xxx\.cn$;
21+
22+
location / {
23+
set $path /root/web/$subdomain;
24+
if (!-d /root/web/$subdomain) {
25+
# 如果前端项目未部署代码,使用默认目录下的前端资源。
26+
set $path /root/web/backend-endpoint;
27+
}
28+
root $path;
29+
index index.html;
30+
if ($uri != "/") {
31+
rewrite ^/(.*)/ /$1/index.html break;
32+
}
33+
}
34+
35+
location /api {
36+
proxy_redirect off;
37+
proxy_http_version 1.1;
38+
proxy_set_header Upgrade $http_upgrade;
39+
proxy_set_header Connection "upgrade";
40+
proxy_set_header Host $host;
41+
proxy_set_header X-Real-IP $remote_addr;
42+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
43+
44+
proxy_pass http://$subdomain;
45+
proxy_connect_timeout 1200s;
46+
proxy_send_timeout 1200s;
47+
proxy_read_timeout 1200s;
48+
proxy_request_buffering off;
49+
proxy_buffering off;
50+
client_max_body_size 20m;
51+
52+
proxy_next_upstream error timeout http_500 http_502;
53+
54+
error_page 502 = @502;
55+
}
56+
57+
location @502 {
58+
# 如果后端未部署对应的代码,则重定向到默认的 main-latest 服务。
59+
add_header 'Access-Control-Allow-Origin' * always;
60+
add_header 'Access-Control-Allow-Credentials' true always;
61+
add_header 'Access-Control-Allow-Methods' * always;
62+
add_header 'Access-Control-Allow-Headers' 'Content-Type,*' always;
63+
add_header 'Access-Control-Request-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
64+
65+
if ($request_method = 'OPTIONS') {
66+
return 204;
67+
}
68+
69+
proxy_redirect off;
70+
proxy_http_version 1.1;
71+
proxy_set_header Upgrade $http_upgrade;
72+
proxy_set_header Connection "upgrade";
73+
proxy_set_header Host $host;
74+
proxy_set_header X-Real-IP $remote_addr;
75+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
76+
77+
proxy_pass http://main-latest;
78+
proxy_connect_timeout 1200s;
79+
proxy_send_timeout 1200s;
80+
proxy_read_timeout 1200s;
81+
proxy_request_buffering off;
82+
proxy_buffering off;
83+
client_max_body_size 20m;
84+
85+
proxy_next_upstream error timeout http_500 http_502;
86+
}
87+
}
88+
```

0 commit comments

Comments
 (0)