Node.js前端程式通過Nginx部署後刷新出現404問題的解決辦法
阿新 • • 發佈:2018-12-20
方案一 (這種方式容易被第三方劫持)
location / {
root
/data/nginx/html
;
index index.html index.htm;
error_page 404
/index
.html;
}
location / {
root
/data/nginx/html
;
index index.html index.htm;
if
(!-e $request_filename) {
rewrite ^/(.*)
/index
.html last;
break
;
}
}
方案三 (vue.js官方教程裡提到的
https://router.vuejs.org/zh-cn/essentials/history-mode.html)
server {
listen 80;
server_name localhost;
root
/data/wwwroot/dist
;
location / {
try_files $uri $uri/ @router;
index index.html index.htm;
}
location @router {
rewrite ^.*$
/index
.html last;
}
}
參考以下兩位大神的部落格:
https:
//blog
.csdn.net
/u011025083/article/details/80352301
https:
//www
.jianshu.com
/p/02ad1f919471