背景介紹:
解決react router 打包之後部署在Nginx子目錄下,在子頁面刷新時會報404的問題。
看錯誤截圖
修改Nginx配置文件 nginx/conf.d/default.conf 文件,配置如下:
#lifecoach
location ~ /lifecoach{
#禁用緩存
#proxy_buffering off;
root /data/ng_src_file;
try_files $uri /lifecoach/index.html; # 在所有路由下刷新都重新指向index.html
}
開始使用配置如下,這個配置會報標題中的錯誤:
location ~ /lifecoach{
#禁用緩存
#proxy_buffering off;
rewrite .* /lifecoach/index.html break; # 這個配置不行,會報標題中的錯誤
root /data/ng_src_file;
}