If you've used Django with Nginx, you are probably familiar with how to configure the Nginx process group to reverse proxy to a second Gunicorn or uWSGI Django process group. (The proxy_pass Nginx parameter passes traffic through Nginx to Django.)
One benefit of this approach is that if your Django process crashes or if you are preforming an upgrade and take Django offline, Nginx can still be available to serve static content and offer some sort of "the system is down" message to users. With just a few lines of configuration, Nginx can be set to automatically display a splash page in the above scenarios.
If the Django process running behind the reverse proxy becomes unavailable, a 502 error will be emitted by Nginx. By default, that 502 will be returned to the browser as an ugly error message. However, Nginx can be configured to catch that 502 error and respond with custom behavior. Specifically, if a 502 is raised by Nginx, Nginx can check for a custom html error page document and serve up that document if it exists. If that document does not exist, Nginx can just return the default ugly 502 error message. The Nginx configuration below executes this described behavior.
This Nginx example is stripped down to just demonstrate the concept described. It only shows the server section portion of the Nginx config. This example assumes that you have created your custom error page at the following location: /sites/joejasinski/htdocs/50x.html.
server.conf
...
# reverse proxy boilerplate
One benefit of this approach is that if your Django process crashes or if you are preforming an upgrade and take Django offline, Nginx can still be available to serve static content and offer some sort of "the system is down" message to users. With just a few lines of configuration, Nginx can be set to automatically display a splash page in the above scenarios.
If the Django process running behind the reverse proxy becomes unavailable, a 502 error will be emitted by Nginx. By default, that 502 will be returned to the browser as an ugly error message. However, Nginx can be configured to catch that 502 error and respond with custom behavior. Specifically, if a 502 is raised by Nginx, Nginx can check for a custom html error page document and serve up that document if it exists. If that document does not exist, Nginx can just return the default ugly 502 error message. The Nginx configuration below executes this described behavior.
This Nginx example is stripped down to just demonstrate the concept described. It only shows the server section portion of the Nginx config. This example assumes that you have created your custom error page at the following location: /sites/joejasinski/htdocs/50x.html.
server.conf
...
# reverse proxy boilerplate
upstream app_server {
server unix:/sites/joejasinski/var/run/django.socket;
}
server {
listen 443;
server_name joejasinski.com www.joejasinski.com;
...
# if Django is unreachable, a 502 is raised...
error_page 502 @502;
location @502 {
root /sites/joejasinski/htdocs/;
# try to load a file called 50x.html at the document root
# or re-raise a generic 502 if no such file is present.
try_files /50x.html =502;
}
# reverse proxy boilerplate for hosting the Django app
location / {
try_files $uri @proxy_to_app;location / {
}
# reverse proxy boilerplate for hosting the Django app
location @proxy_to_app {
....
proxy_pass http://app_server;
}
This behavior is desirable since Django has it's own error handler for handling 50x errors within the application; we want Nginx to display an error page when Django is down, but Django should handle all errors generated by itself.
Note: you can change this behavior to have Nginx handle any error generated by the reverse proxied application. This can be done with the proxy_intercept_errors Nginx parameter.
Note: using a similar approach to the above, you can also create error Nginx-based error handlers for other error codes generated by Nginx.
In summary, this approach allows you to automatically show users a friendly error page if your Django process crashes or is down for maintenance.
# reverse proxy boilerplate for hosting the Django app
location @proxy_to_app {
....
proxy_pass http://app_server;
}
}
It's worth mentioning that, by default, if your Django app raises a 502 error behind the reverse proxy, Nginx will not catch it and thus will not respond with the custom Nginx 502 page. The Nginx 502 error page is only displayed for 502 errors that originate from Nginx; an unavailable reverse proxy application qualifies as such.
This behavior is desirable since Django has it's own error handler for handling 50x errors within the application; we want Nginx to display an error page when Django is down, but Django should handle all errors generated by itself.
Note: you can change this behavior to have Nginx handle any error generated by the reverse proxied application. This can be done with the proxy_intercept_errors Nginx parameter.
Note: using a similar approach to the above, you can also create error Nginx-based error handlers for other error codes generated by Nginx.
In summary, this approach allows you to automatically show users a friendly error page if your Django process crashes or is down for maintenance.
I think you misguide with article title. Because for maintenance page more suitable is 503 status code.
ReplyDelete
ReplyDeleteThis blog website is pretty cool! How was it made !
App Maintenance
ReplyDeleteThanks for sharing your ideas with us and add more information like this.
Drupal Training in Chennai
Drupal Training in Anna Nagar
Drupal Training in Tnagar
Photoshop Classes in Chennai
Best Photoshop Training in Chennai
Photoshop Course Training in Chennai
Manual Testing Training in Chennai
Mobile Testing Training in Chennai
I have read your blog and i got a very useful and knowledgeable information from your blog.You have done a great job
ReplyDeleteMicrosoft Windows Azure Training | Online Course | Certification in chennai | Microsoft Windows Azure Training | Online Course | Certification in bangalore | Microsoft Windows Azure Training | Online Course | Certification in hyderabad | Microsoft Windows Azure Training | Online Course | Certification in pune
ROWE ROWE
ReplyDeleteROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
ReplyDeleteROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
Nice list of bloggers. From this blog I learned more and got to know more .Thank you for sharing this great post. Website Designer San Antonio
ReplyDeleteWow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot.
ReplyDeleteJava Training in Chennai
Java Course in Chennai
You have shared a nice article here about this topic. Your article is very informative and nicely describes about heaters. Thanks for sharing this article here.Branding Companies Vancouver
ReplyDeleteWonderful Article, which define very interesting information about the topic.Thanks for taking your time to share Maintenance Web Page If you wants more related services then must visit DP Websolutions.
ReplyDeleteI read your post and got it quite informative. I couldn't find any knowledge on this matter prior to. I would like to thank you for sharing this article here. web design clark county wa
ReplyDeleteThis post is really awesome. Genuinely i like this blog. It gives me more useful information. I hope you share lots of things with us .Internet marketing company
ReplyDeleteGreat!so fantastic, so inspiring .this is really amazing. i learned new information. thank you so much for sharing this great post. nidhi software company in india
ReplyDeleteI am attracted by the info which you have provided in the above post. It is genuinely good and beneficial info for us. Continue posting, Thank you.Miami website designer
ReplyDeleteThis post is so useful and valuable to increase our knowledge. I am happy that you have shared great info with us. software company in india Grateful to you for sharing an article like this.
ReplyDeleteThank you for providing me with such valuable information about magento conversion rate optimization. This article provided me with some useful knowledge. Continue to make posts like this.
ReplyDeleteThanks for your post. It's very helpful post for us. You can also visit web design Vancouver WA for more Victor Steel related information. I would like to thanks for sharing this article here.
ReplyDeleteI read the above article and I got some different kind of information from your article about a mattress. It is a helpful article to enhance our knowledge for us. Thankful to you for sharing an article like this.Website Designing Course in Delhi
ReplyDeleteGreat blog ! I am impressed with suggestions of author. handyman services ottawa
ReplyDeleteYou have worked nicely with your insights that makes our work easy. The information you have provided is really factual and significant for us. Keep sharing these types of article, Thank you.Social Media Marketing Company in Fort St John
ReplyDeleteFound your post interesting to read. I can't wait to see your post soon. Good Luck with the upcoming update. This article is really very interesting and effective. website developer near me
ReplyDelete