0

当我遇到 403 错误时,我想在本地开发环境中提供 403 模板,但想在 uat/prod 上为相同的错误渲染 404 模板。

我试过了

error_page 400 /error/400.html;
error_page 404 /error/404.html;
error_page 403 /error/403.html;
error_page 500 502 503 504 /error/50x.html;

location ^~ /error/ {
     internal;
     if ($server_name != "localhost") {
         return 404 /error/404.html;
     }
     root /etc/nginx;
}

error_page 400 /error/400.html;
error_page 404 /error/404.html;
if ($server_name != "localhost") {
   error_page 403 /error/404.html;
}
error_page 403 /error/403.html;
error_page 500 502 503 504 /error/50x.html;

location ^~ /error/ {
     internal;
     root /etc/nginx;
}

但两者都不起作用。我最近才开始学习 nginx,所以上面的做法可能完全错误。想知道有没有人有什么好主意?

提前谢谢了!

4

0 回答 0