Press "Enter" to skip to content

Antd 添加维护页面

  • 产生问题

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 $uri $uri/ /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 $uri $uri/ /index.html;
    }

    ......

}
    发表回复

    您的电子邮箱地址不会被公开。 必填项已用 * 标注