Skip to content

Instantly share code, notes, and snippets.

@denji
Last active January 5, 2017 12:25
Show Gist options
  • Select an option

  • Save denji/8854326 to your computer and use it in GitHub Desktop.

Select an option

Save denji/8854326 to your computer and use it in GitHub Desktop.
HTTP 503: Handling site maintenance correctly for SEO
# http://mailman.nginx.org/pipermail/nginx/2011-November/030165.html
http {
# …
server {
# …
# location / {
# # …
# try_files … @error503 ;
# }
# …
# location @error503 {
# error_log logs/qdvd.error.log debug ;
# expires -1;
# add_header Retry-After 604800; # 7*24*60*60 = 604800
# #return 503; # HTTP 503 Service Unavailable
# return 204; # HTTP 204 No Content
# }
}
}
<?php
header( "{$_SERVER['SERVER_PROTOCOL']} 503 Service Unavailable", true, 503 );
header( 'Retry-After: 3600' );
@StephanGeorg

Copy link
Copy Markdown

Why do you return a 204 instead of 503?

@denji

denji commented Jan 5, 2017 •

Copy link
Copy Markdown
Author

@StephanGeorg (503 || !try_files = 204 log(debug)) https://nginx.org/r/try_files
503 Service Unavailable instead can say that the webserver is not ready to get to work next time with a delay
2xx 204 http server response ok, but not cache body (No Content) (not update).

The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.

You can modulate your behavior if necessary.

@StephanGeorg

Copy link
Copy Markdown

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment