服务器部署vue+nginx配置

Linux || unbuntu 环境下部署vue+nginx配置

nginx 配置
1
2
//修改nginx.conf配置文件,在http下面添加一行代码:include vhost/*.conf; 表示每个项目单独配置,方便管理.
include shadow/*.conf;
conf文件夹下面建立shadow文件夹,再在shadow 下面建立vue.conf 放入一下内容:
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
server {
#端口
listen 80;
#设置文件存放路径
root /srv/view/dist/;
index index.html;

server_name www.shadow.com;

#图片代理
location /images {
proxy_pass http://127.0.0.1:3000;
}

location / {
try_files $uri $uri/ /index.html;
}

#接口代理
location /api {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:3000;
}
}
//其他路径配置:
location /vue/ {
try_files $uri $uri/ @router;
}
location @router {
rewrite ^.*$ /vue/index.html last;
}
shadow wechat
扫一扫,关注微信公众号。