Debugging django on nginx Server Error (500) - django

Running django on nginx on my staging server I've got Server Error (500). Following this question I've set
ALLOWED_HOSTS = ['*']
But that did not solve my problem.
Does anyone know how I can see djangos exceptions?

Django sends an E-Mail to all ADMINS, when DEBUG is False and some EMAIL_* settings are properly set.
See:
https://docs.djangoproject.com/en/1.10/howto/error-reporting/
You can also setup an appropriate logging to do that:
https://docs.djangoproject.com/en/1.10/topics/logging/
for more information.

Related

Axios with django server on localhost

Trying to access django server on localhost from my react native app. All I get is Network Error, which doesn't say much. Tried changing info.plist file as suggested in other answers on stack, tried changing firewall settings and so on.
The thing that worked and solved all my problems was changing the url on axios to my local ip and running django server with command: python manage.py runserver 0.0.0.0 which to my understanding will accept any connection to the server.

Setting up a Django server with Gunicorn and Nginx

I've followed this tutorial and i'm running into an ERR_SSL_PROTOCOL_ERROR that i just can't figure out.
I must mention that i have set inside settings.py:
DEBUG = FAlSE
SECURE_SSL_REDIRECT = False
And my Allowed_hosts is ['*'].
I have a number of questions which reading alot of blog posts hasn't answered:
In the nginx configuration, if i'm running the server from a laptop connected to a router, and the external IP is 12.34.56.78 and the port is 50000, what am i supposed to put at server_name?
In the gunicorn configuration, everyone states that this is the config command: gunicorn --bind 0.0.0.0:8800 AWESOME.wsgi:application what IP should i put there in my case? 12.34.56.78:50000 or just leave it like it is?
As i understand the situation, given the setting in django settings.py my server is not serving HTTPS so the error does not come from that. I've also read about certbot but since i don't have even those 2 above questions figured out i cannot understand how to configure certbot..
EDIT
In fact i've tried to:
gunicorn --bind 12.34.56.78:50000 KYng.wsgi:application but i'm getting invalid address error
1.) You actually don't need to put anything in there, as it will default to an empty string.
2.) You should put localhost (127.0.0.1) if you want it to run locally, or 0.0.0.0 if you want it to run publicly.
Concerning the ssl error, check your nginx configuration more closely...that you didn't reference https instead of http somewhere...

Redirect http to https in Django (using sslserver)

I have a django project working with HTTPS using django sslserver.I want http to be redirected to https. I tried adding SECURE_SSL_REDIRECT = True which does not seem to have any effect.
Similarly to test if my redirection was right, I tried the following on a test project.
Created a new django project
Added SECURE_SSL_REDIRECT = True to the settings.py file. Here now, when I try to run the server with http it redirects to https. But asof now my server does not support https cause of which desired web page is not displayed.
Installed sslserver
Ran the project with the command python manage.py runsslserver 8000
This succesfully redirects the webpage to https even if I open the url with http
This test redirection works fine like this. But if I already have sslserver installed ssl redirection does not seem to have any effect. I have been stuck with this problem for a while now and would really appreciate some help.
SECURE_SSL_REDIRECT settings works together with SecurityMiddleware.
Try add it to MIDDLEWARE_CLASSES in settings.py.
In addition to SECURE_SSL_REDIRECT=True in settings.py as mentioned, you need both
runsslserver on port 443
runserver on port 80
To have another service listen on port 80 for incoming http requests and do the redirect.
That works for me.
try adding to your settings.
ACCOUNT_DEFAULT_HTTP_PROTOCOL = 'https'

django debug false and internal server error

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?

Why am I getting an apache server error page on a django vhost using underscore in my subdomain?

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