Vue 项目的 Nginx 基础配置
Teo 2021/10/29 Nginx服务器
# nginx 配置
最好是根据项目名称或者域名来命名 .conf 文件
比如 teojs.com.conf
、your_project.conf
# 注释版
server {
listen 80;
# 监听 https 端口,要写ssl,不要用ssl on,否则会http会访问不了
listen 443 ssl;
# 域名,多个用空格分开
server_name teojs.com www.teojs.com;
# 配置上传大小限制
client_max_body_size 10M;
# 证书配置,没有可以删除
ssl_certificate your_ssl_cert.pem;
ssl_certificate_key your_ssl_cert.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE;
ssl_prefer_server_ciphers on;
# vue项目静态文件
location / {
root /your_project_directory;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
# 接口反代
location /api/ {
proxy_pass http://127.0.0.1:1024/;
proxy_set_header Host $http_host;
}
}
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
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
# 无注释版
server {
listen 80;
listen 443 ssl;
server_name teojs.com www.teojs.com;
client_max_body_size 10M;
ssl_certificate your_ssl_cert.pem;
ssl_certificate_key your_ssl_cert.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE;
ssl_prefer_server_ciphers on;
location / {
root /your_project_directory;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://127.0.0.1:1024/;
proxy_set_header Host $http_host;
}
}
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
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
# 强制 https
需要拆开写,在监听 80 端口那里写 return 301 https://$server_name$request_uri;
server {
listen 80;
server_name teojs.com www.teojs.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name teojs.com www.teojs.com;
ssl on;
client_max_body_size 5m;
ssl_certificate your_ssl_cert.pem;
ssl_certificate_key your_ssl_cert.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE;
ssl_prefer_server_ciphers on;
location / {
root /your_project_directory;
index index.html index.htm;
try_files $uri $uri/ /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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25