轉(zhuǎn)自https://www.cnblogs.com/Mr-Rshare/p/11543178.html
僅供自我學(xué)習(xí),侵刪
對于VUE的router[mode: history]模式(這里主要是為了去除鏈接上的"#")
開發(fā)的時(shí)候,一般都不出問題。是因?yàn)殚_發(fā)時(shí)用的服務(wù)器為node,Dev環(huán)境中已配置好了,
nginx運(yùn)行的時(shí)首頁沒有問題,鏈接也沒有問題,但在點(diǎn)擊刷新后,頁面就會(huì)顯示(404)
原配置:
location / {
root /home/testhadoop/www/html;
index index.html index.htm;
}
解決方案如下:
方案一:
使用try_files
語法:try_files file1 [file2 ... filen] fallback
location / {
root /home/testhadoop/www/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
方案二:
使用try_files
location /{
root /home/testhadoop/www/html;
index index.html index.htm;
if (!-e $request_filename) {
rewrite ^/(.*) /index.html last;
break;
}
}
方案三:
使用error_page (一般不建議用, 404的方式會(huì)被第三方劫持)
location /{
root /home/testhadoop/www/html;
index index.html index.htm;
error_page 404 /index.html;
}