我使用 nginx 作为我的项目的代理服务器。如果我的应用离线进行维护,我想显示一个后备页面。到目前为止,这工作正常。唯一的问题是,带有 502 错误代码的服务器响应 - 这是有道理的。但是,如何在回退中将其更改为 503 路由?
server {
listen 80;
error_page 500 502 503 504 @fallback;
location / {
proxy_pass http://0.0.0.0:3000;
}
location @fallback {
// I need this to answer with a status of 503 instead of a 502
root /srv/my-project/static;
try_files /fallback.html;
}
}
Run Code Online (Sandbox Code Playgroud)
你可以设置一个错误页面nginx错误页面
并设置类似
error_page 502 =503 /maintenance.html
或类似的东西
location / {
error_page 502 =503 /maintenance.html;
include proxy_params;
proxy_pass http://unix:/var/run/my.sock;
}
location /maintenance.html {
return 503;
}
Run Code Online (Sandbox Code Playgroud)
来源:当我的代理应用服务器关闭时,如何让 Nginx 返回 HTTP 503?
| 归档时间: |
|
| 查看次数: |
939 次 |
| 最近记录: |