#处理vue出现404
#需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404
location / {
try_files $uri $uri/ @router;
index index.html index.htm;
}
#对应上面的@router,主要原因是路由的路径资源并不是一个真实的路径,所以无法找到具体的文件
#因此需要rewrite到index.html中,然后交给路由在处理请求资源
location @router {
rewrite ^.*$ /index.html last;
}
#端口代理
location /prod-api {
#重定向去除/prod-api
rewrite ^/prod-api(.*)$ $1 break;
proxy_pass http://127.0.0.1:8100;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
vue项目配置nginx
于 2025-03-29 15:11:40 首次发布