When something goes wrong the server returns the default nginx 502 Server Error, I'd like to show my own server error page.
I put 502.html file to the template directory but it doesn't seem to work. It works for 404.html so I am sure I put it to the right directory.
Any ideas how to solve this problem or what could I miss?
Since 502 means "Bad Gateway", Django (or even the WSGI server in between) is not aware of the request at all. You can add a line similar to the following to your NginX configuration file:
error_page 502 /var/www/502.html;
Related
My django website sometimes cannot open images and the error message is:
"Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH"
However, when I open the link next to the error message on a new tab, the image is loading. I am using Apache, not nginx.
Here's how image looks like when I tried to open on a new window
As you can see it's not fully loaded!
Could someone help me with this problem?
Finally, I was able to fix it. Of course it was an apache problem. First I have activated my sudo a2enmod expires then added ExpiresDefault "access plus 1 month" to my media and static Directory in mysite.conf file.
When I try to open my instance via the Public DNS, I get a 404 error.
However, in my security group, I have HTTP/HTTPS/SSH configured to allow all incoming requests. When I connect to the instance via SSH, I can see all of my files there from my repo.
I am running on an Ubuntu 64-bit server with Nginx and Gunicorn.
Any help would be appreciated.
Thank you in advance!
Two possibilities for getting 404 file not found error
Make sure /usr/share/nginx/html/index.html is found or not.
check with nginx.conf file, if it is directing to index.html or not.
im writing a project using django.
while it was in a development stage i used DEBUG=TRUE, but now i want to upload it to heroku for production.
i set DEBUG=FALSE and kept getting an internal server error, so i further investigated and found that i need to set ALLOWED_HOSTS = ['localhost', '127.0.0.1'], so i did..
i ran it with the localhost but i still kept getting internal server error.
what am i doing wrong? cause i can't figure it out?
also, what should i put in allowed host for heroku site?
thanks
try this
python manage.py collectstatic
Remember that static files directory when debug = true is no the same when debug is false
heroku uses whitenoise for static files.
You need the domain you're accessing your server from in ALLOWED_HOSTS.
Example:
ALLOWED_HOSTS = ['www.example.com', ]
Yet, improperly configured ALLOWED_HOSTS should not result in internal server error responses (HTTP code 500) but in bad request responses (HTTP code 400).
Have you configured a way to log exceptions on your production server in order to investigate this?
I'm using django 1.5.0 and apache 2.2.22. I can't seem to get my site running as a named vhost (I've got other django sites already running fine on this server).
I'm getting the standard apache 500 error page. My error log suggests that've I've got a problem with my ALLOWED_HOSTS setting -
[Tue Jun 04 10:25:22 2013] [error] [client 31.52.39.247] SuspiciousOperation: Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): sub_domain.mydomain.com
But my ALLOWED_HOSTS setting looks ok to me -
python manage.py shell
>> from django.conf import settings
>> settings.ALLOWED_HOSTS
['sub_domain.mydomain.com', 'livedomain.com']
Also - I don't know why I'm getting the apache 500 page rather than the django debug page -
>> settings.DEBUG
True
Looking at the full stack trace in the error log, I can see that the wsgi app is running - it's definitely running django code.
Any suggestions?
Firstly, ALLOWED_HOSTS should be ignored altogether when you have DEBUG=True so that's strange that you are getting validation errors.
I was having an issue similar to this with nginx where I had an underscore in my host name which meant Django didn't validate it. This might be an issue particularly if you are having Apache rewriting your host header (this was the case for me as nginx was reverse proxying) or your subdomain includes an _.
You can see how Django validates hostnames in the source, furthermore, I wrote a quick blog post on this also which might help
I'm hosting on hostgator and using fcgi for my django app, its a sharedhost so I dont have much choice about flup and fcgi. When Debug = False I get a fcgi Unhandled Exception page instead of a Apache 404 error even though with Debug = True I would be getting a 404 from django/python.
Do I have to catch the python 404 exceptions in the fcgi file or should they just bubble up to Apache?
404 produces 500 Internal server error if your DEBUG is False and you do not have templates for 404. Make sure that you have 404.html and 500.html in your templates directory. Also have a look error logs in your admin email.