nginx部署vue工程和反向代理nodejs工程

前端是vue,后端是nodejs

前端打包成dist目录,后端接口是localhost:4000/api

server
{
listen 80;
#listen [::]:80;
server_name yourdomain;
index index.html;
root /home/wwwroot/yourfolder/dist; # vue router开启了history 模式,nginx匹配不到的路由,就返回index.html,这样不报404
location / {
try_files $uri $uri/ /index.html;
}
# 反向代理
location /api/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass http://127.0.0.1:4000/api/;
} location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
} location ~ .*\.(js|css)?$
{
expires 12h;
} location ~ /.well-known {
allow all;
} location ~ /\.
{
deny all;
} access_log off;
}
上一篇:docker部署jar工程


下一篇:Docker部署Vue