如何用nginx将vue部署到本地




server { listen
9000; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; try_files $uri $uri/ /index.html; //据说加上这个玩意 刷新页面不会404
index index.html index.htm; } location @router { rewrite
^.*$ /index.html last; } location ^~/api/ { proxy_pass http://xxx.xx.x.xx:xxxx/; //后面这个斜杠 应该是可以代替重写 proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }

这边主要是因为 打包之后,连登陆接口都访问不了,一直 404. 说实话 上面的一串玩意一个看不懂。。。。

转自: 

https://juejin.cn/post/6857787591301005320#heading-7

原文地址:https://www.cnblogs.com/diligent-noob/p/14788676.html