当我的代理应用程序服务器closures时,如何让Nginx返回HTTP 503?

我有一个坐在运行Web应用程序的Jetty Java应用程序服务器前面的nginx web服务器。

如果代理Jetty服务器closures,我想configurationnginx返回一个HTTP 503。

这样,当我将应用程序服务器closures以进行维护时,如果发生故障,503会返回给任何客户端,让他们知道该站点暂时不可用。

但是,使用基本configuration,当Nginx无法连接到proxy_pass位置时,会返回HTTP 502 Bad Gateway。

有没有可能configurationnginx报告一个503呢?

你可以通过设置错误页面来完成 。

error_page 502 =503 /maintenance.html 

只用Martin Fjordvald的答案的内容,我仍然得到502,我没有一个真正的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; }