- 产生问题
Antd项目每次build时,访问页面抛出500错误。于是,打算加一个error_page来表示项目正在维护
- Nginx配置500页面模板
server {
......
fastcgi_intercept_errors on;
error_page 500 /500.html;
location = /500.html {
root /template_file_path;
}
......
}
- 重启Nginx后不生效
查看error.log
... rewrite or internal redirection cycle while internally redirecting to "/index.html", client: ...
分析:build项目时rm -rf dist/
导致根目录index.html不存在,而重写又使页面反复重定向(redirection cycle)到index.html
location / {
try_files uriuri/ /index.html;
}
- 解决
在server中加入下面配置
location /index.html {
rewrite ^ /index.html break;
}
当index.html不存在时,跳出不再循环重定向,直接返回404错误
- 完整配置
server {
......
fastcgi_intercept_errors on;
error_page 404 /maintenance.html;
location = /maintenance.html {
root /template_file_path;
}
location /index.html {
rewrite ^ /index.html break;
}
location / {
try_files uriuri/ /index.html;
}
......
}