# 一.项目中配置
# 1.dev配置
server {
server_name dev.zhoubichuan.com;
location ~*^.+$ {
gzip on;
gzip_min_length 1k;
gzip_http_version 1.1;
gzip_comp_level 9;
gzip_types text/css application/javascript;
root /usr/src/zhoubichuan/dev/;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location ^~/common-node/api {
proxy_pass http://localhost:3000/api;
}
location ^~/antdpro-express/api {
proxy_pass http://localhost:7001/api;
}
location ^~/abstract-express/api {
proxy_pass http://localhost:7005/api;
}
location ^~/abstract-egg/api {
proxy_pass http://localhost:7006/api;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 2.sit配置
server {
server_name sit.zhoubichuan.com;
location ~*^.+$ {
gzip on;
gzip_min_length 1k;
gzip_http_version 1.1;
gzip_comp_level 9;
gzip_types text/css application/javascript;
root /usr/src/zhoubichuan/sit/;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location ^~/common-node/api {
proxy_pass http://localhost:3000/api;
}
location ^~/antdpro-express/api {
proxy_pass http://localhost:7001/api;
}
location ^~/abstract-express/api {
proxy_pass http://localhost:7005/api;
}
location ^~/abstract-egg/api {
proxy_pass http://localhost:7006/api;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 3.uat配置
server {
server_name uat.zhoubichuan.com;
location ~*^.+$ {
gzip on;
gzip_min_length 1k;
gzip_http_version 1.1;
gzip_comp_level 9;
gzip_types text/css application/javascript;
root /usr/src/zhoubichuan/uat/;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location ^~/common-node/api {
proxy_pass http://localhost:3000/api;
}
location ^~/antdpro-express/api {
proxy_pass http://localhost:7001/api;
}
location ^~/abstract-express/api {
proxy_pass http://localhost:7005/api;
}
location ^~/abstract-egg/api {
proxy_pass http://localhost:7006/api;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 4.pet配置
server {
server_name pet.zhoubichuan.com;
location ~*^.+$ {
gzip on;
gzip_min_length 1k;
gzip_http_version 1.1;
gzip_comp_level 9;
gzip_types text/css application/javascript;
root /usr/src/zhoubichuan/pet/;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location ^~/common-node/api {
proxy_pass http://localhost:3000/api;
}
location ^~/antdpro-express/api {
proxy_pass http://localhost:7001/api;
}
location ^~/abstract-express/api {
proxy_pass http://localhost:7005/api;
}
location ^~/abstract-egg/api {
proxy_pass http://localhost:7006/api;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 5.sim配置
server {
server_name sim.zhoubichuan.com;
location ~*^.+$ {
gzip on;
gzip_min_length 1k;
gzip_http_version 1.1;
gzip_comp_level 9;
gzip_types text/css application/javascript;
root /usr/src/zhoubichuan/sim/;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location ^~/common-node/api {
proxy_pass http://localhost:3000/api;
}
location ^~/antdpro-express/api {
proxy_pass http://localhost:7001/api;
}
location ^~/abstract-express/api {
proxy_pass http://localhost:7005/api;
}
location ^~/abstract-egg/api {
proxy_pass http://localhost:7006/api;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 6.prod配置
server {
server_name zhoubichuan.com; # 填写相应的子域名,不需要加 https:// 的前缀。填写这个使得 Nginx 可以正确匹配不同子域的请求
location ~*^.+$ {
gzip on;
gzip_min_length 1k;
gzip_http_version 1.1;
gzip_comp_level 9;
gzip_types text/css application/javascript;
root /usr/src/zhoubichuan/prod/; # 指示这个子域名所对应的文件夹根目录的位置
try_files $uri $uri/ /index.html;
index index.html index.htm; # 显示主页时所使用的文件名
}
location ^~/common-node/api {
proxy_pass http://localhost:3000/api;
proxy_http_version 1.1; # 设置 HTTP 版本,SSE 需要 HTTP/1.1
proxy_set_header Connection ''; # 保持连接活性,不发送连接关闭的信号
proxy_buffering off; #不对 SSE 响应进行缓冲,直接透传给客户端
proxy_cache off; # 关闭代理缓存
proxy_read_timeout 3600s; # 设置代理读取服务器响应的超时时间
proxy_send_timeout 3600s;
proxy_connect_timeout 1h; # 设置客户端连接的超时时间
proxy_set_header Host $host; # 配置代理传递的头部,确保 Host 头部正确传递
proxy_set_header X-Accel-Buffering no; # 设置代理的响应头部,保持传输编码为 chunked
add_header Cache-Control no-cache;
# add_header X-Accel-Buffering "no";
chunked_transfer_encoding on; # 启用分块传输编码
gzip off;
# 设置跨域资源共享 (CORS),如果你的客户端和服务器不在同一个域上
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Origin,Authorization,Accept,X-Requested-With' always;
if ($request_method = 'OPTIONS') {
# 如果请求方法为 OPTIONS,则返回 204 (无内容)
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Origin,Authorization,Accept,X-Requested-With';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
location ^~/antdpro-express/api {
proxy_pass http://localhost:7001/api;
}
location ^~/abstract-express/api {
proxy_pass http://localhost:7005/api;
}
location ~* ^(/api/docs/) {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
#proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_pass http://localhost:7005; # 后端服务地址
}
location ^~/abstract-egg/api {
proxy_pass http://localhost:7006/api;
}
location ^~/child/resume {
root html;
index index.html index.htm;
try_files $uri $uri/ /child/resume/index.html;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 7.micro配置
server {
server_name micro.zhoubichuan.com;
location ~*^.+$ {
gzip on;
gzip_min_length 1k;
gzip_http_version 1.1;
gzip_comp_level 9;
gzip_types text/css application/javascript;
root /usr/src/zhoubichuan/micro/;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location ^~/common-node/api {
proxy_pass http://localhost:3000/api;
}
location ^~/antdpro-express/api {
proxy_pass http://localhost:7001/api;
# include /etc/nginx/conf.d/*.conf;
}
location ^~/abstract-express/api {
proxy_pass http://localhost:7005/api;
}
location ^~/abstract-egg/api {
proxy_pass http://localhost:7006/api;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 9.http配置
server {
listen 80; # Nginx 要监听 80 号端口
server_name _; # 无论什么 hostname 都会被匹配
return 301 https://$host$request_uri; # 用户的 HTTP 请求永久重定向(301 Moved Permanently)到 HTTPS 那边,并且保证链接的剩余部分不变
}
1
2
3
4
5
2
3
4
5
# 10.https配置
server {
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/zhoubichuan.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/zhoubichuan.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# 11.默认配置
server {
server_name zhoubichuan.com;
location ~*^.+$ {
gzip on;
gzip_min_length 1k;
gzip_http_version 1.1;
gzip_comp_level 9;
gzip_types text/css application/javascript;
root /usr/src/zhoubichuan/prod/;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location ^~/common-node/api {
proxy_pass http://localhost:3000/api;
}
location ^~/antdpro-express/api {
proxy_pass http://localhost:7001/api;
# include /etc/nginx/conf.d/*.conf;
}
location ^~/abstract-express/api {
proxy_pass http://localhost:7005/api;
}
location ^~/abstract-egg/api {
proxy_pass http://localhost:7006/api;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
1,8 顶端
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/zhoubichuan.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/zhoubichuan.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = zhoubichuan.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name zhoubichuan.com;
return 404; # managed by Certbot
}
89,1 底端
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
刷新
全屏/自适应