如何在 Nginx 中使用自定义 503 错误页面?

Mic*_*uch 9 nginx

我已经使用 Nginx 实现了速率限制(顺便说一下,它工作得很好)并且想显示一个自定义的 503 错误页面。

我在没有运气的情况下遵循了网络上的示例。

我正在运行一个简单的配置,看起来像这样:

listen x.x.x.x:80
server_name something.com
root /usr/local/www/something.com;
error_page 503 /503.html;

location / {
  limit_req zone=default burst=5 nodelay;
  proxy_pass http://mybackend;
}
Run Code Online (Sandbox Code Playgroud)

这个想法是我们的​​限速用户会看到一个特殊的页面,解释正在发生的事情。速率限制有效,但内置 503 页面正在呈现。

有任何想法吗?

小智 5

添加

location = /503.html {
  root /path/to/the/page;
}
Run Code Online (Sandbox Code Playgroud)