Nginx 基础配置
# Nginx 配置
# ip 地址部署三端
# 存放目录
服务器目录: etc -> nginx -> conf.d
# default.conf
server {
listen 80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
# location / {
# root /usr/share/nginx/html;
# index index.html index.htm;
# }
location / {
#root /usr/share/nginx/html;
root /home/h5/dist;
index index.html index.htm;
}
location @router {
rewrite ^.*$ /index.html last; # 关键一句
}
location /cms{
alias /home/admin/dist;
index index.html index.htm;
try_files $uri $uri/ @router;
}
# 图片静态目录
location /uploads {
root /home/server/public;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
# m3u8 静态目录
location /uploads/video {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /home/server/public;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
# location / {
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# proxy_set_header Via "nginx";
# proxy_pass http://localhost:9000;
# }
# 后端代码代理
location ^~ /api/v1 {
proxy_pass http://localhost:9000;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
client_max_body_size 5000m; # 允许客户端请求的最大单文件字节数
client_body_buffer_size 128k; # 缓冲区代理缓冲用户端请求的最大字节数,
proxy_connect_timeout 90; # nginx跟后端服务器连接超时时间(代理连接超时)
proxy_send_timeout 90; # 后端服务器数据回传时间(代理发送超时)
proxy_read_timeout 90; # 连接成功后,后端服务器响应时间(代理接收超时)
proxy_buffer_size 4k; # 设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 4 32k; # proxy_buffers缓冲区,网页平均在32k以下的设置
proxy_busy_buffers_size 64k; # 高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 64k;
}
#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;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# 域名部署三端项目
# 存放目录
服务器目录: etc -> ngnix -> conf.d
# default.conf
server {
listen 80 default_server;
server_name _;
location / {
return 404;
}
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# api.conf
server {
listen 80;
server_name api.xxx.com;
access_log /var/log/nginx/api_access.log main;
# m3u8 静态目录
location /uploads/video {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /home/server/public;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
# 图片静态目录
location /uploads {
root /home/server/public;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
# location / {
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# proxy_set_header Via "nginx";
# proxy_pass http://localhost:9000;
# }
location ^~ /api/v1 {
proxy_pass http://localhost:9000;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
client_max_body_size 5000m; # 允许客户端请求的最大单文件字节数
client_body_buffer_size 128k; # 缓冲区代理缓冲用户端请求的最大字节数,
proxy_connect_timeout 90; # nginx跟后端服务器连接超时时间(代理连接超时)
proxy_send_timeout 90; # 后端服务器数据回传时间(代理发送超时)
proxy_read_timeout 90; # 连接成功后,后端服务器响应时间(代理接收超时)
proxy_buffer_size 4k; # 设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 4 32k; # proxy_buffers缓冲区,网页平均在32k以下的设置
proxy_busy_buffers_size 64k; # 高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 64k;
}
}
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
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
# admin.conf
server {
listen 80;
server_name admin.xxx.com;
access_log /var/log/nginx/admin_access.log main;
location @router {
rewrite ^.*$ /index.html last; # 关键一句
}
# m3u8 静态目录
location /uploads/video {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /home/server/public;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
# 图片静态目录
location /uploads {
root /home/server/public;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
location / {
root /home/admin/dist/;
index index.html index.htm;
#try_files $uri $uri/ @router;
}
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
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
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
# h5.conf
server {
listen 80;
server_name xxx.com www.xxx.com m.xxx.com;
access_log /var/log/nginx/h5_access.log main;
location @router {
rewrite ^.*$ /index.html last; # 关键一句
}
# m3u8 静态目录
location /uploads/video {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /home/server/public;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
# 图片静态目录
location /uploads {
root /home/server/public;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
location / {
#root /usr/share/nginx/html;
root /home/h5/dist;
index index.html index.htm;
}
}
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
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
编辑 (opens new window)
上次更新: 2024/04/20, 18:53:06