< pre>server {
listen 80 default;
root /usr/share/nginx/html;
server_name example.com;
location / {
if (-f $document_root/503.json) {
return 503;
}
}
# error 503 redirect to 503.json
error_page 503 @maintenance;
location @maintenance {
rewrite ^(.*)$/503.json break;
}
}
The problem is found by Nginx Any request is parsed in a static file. Any POST, PUT and DELETE request will get a 405 (Method not allowed) response.
So the question is: How to tell Nginx to provide page services for any HTTP method?
The solution is to capture 405 errors in your @503 location block, serving
the maintenance page. In addition , you will have to enable
@recursiveerrorpages@, since you are first, intentionally, throwing a
503 error, and then the user is throwing a 405 by posting to your
static file:
recursive_error_pages on;
if (-f $document_root/system/maintenance.html) {
return 503;
}
error_page 404 /404.html;
error_page 500 502 504 /500.html;
error_page 503 @503;
location @503 {
error_page 405 = /system/maintenance.html;
# Serve static assets if found.
if (-f $request_filename) {
break;
}
< br /> rewrite ^(.*)$/system/maintenance.html break;
}
Source: https://www.onehub.com/blog/2009/03/06 /rails-mai ntenance-pages-done-right/
I have a simple configuration file for customizing the 503 error page during maintenance. The relevant part is like this:
server {
listen 80 default;
root /usr/share/nginx/html;
server_name example.com;
location / {
if (-f $document_root/503.json) {
return 503;
}
}
# error 503 redirect to 503.json
error_page 503 @maintenance;
location @maintenance {
rewrite ^(.*)$/503.json break;
}
}
The problem is that Nginx finds that any request is parsed in a static file, and any POST, PUT and DELETE request will get a 405 (method not allowed) response.
So the question is: how Tell Nginx to provide page services for any HTTP method?
I ran into this today. It seems that the problem is due to nginx (like most servers) not letting you POST to static files.
The solution is to capture 405 errors in your @503 location block, serving
the maintenance page. In addition, you will have to enable
@recursiveerrorpages@ , since you are first, intentionally, throwing a
503 error, and then the user is throwing a 405 by posting to your
static file:
recursive_error_pages on;
if (-f $document_root/system/maintenance.html) {
return 503;
}
error_page 404 /404.html;
error_page 500 502 504 /500.html;
error_page 503 @503;
location @503 {
error_page 405 = /system/maintenance.html;
< br /> # Serve static assets if found.
if (-f $request_filename) {
break;
}
rewrite ^(.*)$/system /maintenance.html break;
}
Source: https://www.onehub.com/blog/2009/03/06/rails-maintenance-pages-done-right/< /p>