Production Django Application Throwing/Not Throwing 500 Error based on Debug = Value - django

I have an production django application that runs fine with Debug = True; but doesn't with Debug=False.
If I load run the domain, it shows my urls.py file, which is really bad.
I want to get my application where it uses Debug=False and TEMPLATE_DEBUG=False instead of Debug=True and TEMPLATE_DEBUG=True , since by using the True value it exposes the application
If I view my error.log under nginx with DEBUG=True:
2013/10/25 11:35:34 [error] 2263#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xxx.xx.xxx, server: *.myapp.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8001/", host: "www.myapp.com"
view my access.log under nginx with DEBUG=True:
xx.xxx.xx.xxx - - [25/Oct/2013:11:35:33 +0000] "GET / HTTP/1.1" 502 173 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0"
So my question is, why when I set DEBUG=True and TEMPLATE_DEBUG=True does it load successfully showing the application and when I set DEBUG=False and TEMPLATE_DEBUG=False it shows the custom http 500 error page? (I have created to handle http 500 errors)

Thanks to Toad013 and Dmitry for their suggestions.
It appears the issue might have been with how nginx and gunicorn were being started and not a configuration issue, thus, I ended up using the following to start my app:
/usr/local/bin/gunicorn -c /home/ubuntu/virtualenv/gunicorn_config.py myapp.wsgi
sudo nginx -c /etc/nginx/nginx.conf

Related

Django on Digitalocean with Python and Gunicorn throws 500 error no matter the Debug settings

I'm REALLY confused. Ive been using the same settings for years and they have worked great... until today.
Setup:
Django on Gunicorn with NGINX on Digitalocean
Python 3
Anytime I go to a URL it looks liek the 500 error is being triggered and then the 500.html template is displayed. But this is happening regardless of the Debug settings. Additionally, there is nothing that is being written to the Gunicorn errors. The only error I'm getting is a 404 on the template directory.
As a sanity check, here is some sample configurations that I'm using.
NGINX Location:
root /home/myname/myrepoproject;
error_page 500 502 503 504 /500.html;
location = /500.html {
root /home/myname/myrepoproject/myproject/app/templates;
}
NGINX Error:
2018/03/26 17:09:14 [crit] 3267#3267: *35 connect() to unix:/home/myname/myproject/myproject.sock failed (2: No such file or directory) while connecting to upstream, client: XXX.XXX.XXX.XXX, server: ZZZ.ZZZ.ZZZ.ZZZ, request: "GET /500.html/ HTTP/1.1", upstream: "http://unix:/home/myname/myproject/myproject.sock:/500.html/", host: "arecord.domain.name"
Gunicorn ExecStart:
ExecStart=/home/myname/.virtualenvs/myve/bin/gunicorn --error-logfile ~/logs/gunicorn/gunicorn-errors.log --workers 3 --bind unix:/home/myname/myve/myproject.sock production
The static and upload directories work.
Any troubleshooting ideas welcome.
From the errors you posted it looks like your nginx and gunicorn configs do not have the same location set of the socket so they fail to communicate.
Nginx is looking at unix:/home/myname/myproject/myproject.sock but your gunicorn command line says --bind unix:/home/myname/myve/myproject.sock.
Make them match and it should work.

Where is the uWSGI (error) log file when installing uWSGI using pip?

I'm trying to run my Django app using Nginx and uWSGI. When I try to go to
127.0.0.1:8001/media/media.png
Nginx properly shows the image, but when I go to
127.0.0.1:8000/CMS/users
Django is supposed to call a view. Instead, Nginx returns a 504 Gateway Time-out. When I view the Nginx error log, it says
*6 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 127.0.0.1, server: 192.168.174.131, request: "GET /CMS/users HTTP/1.1", upstream: "uwsgi://127.0.0.1:8001", host: "127.0.0.1:8000"
Does a uWSGI error log file exist? If yes, where can I find it? (I'm searching for it because I think it might help debug the issue).
Note: I installed uwsgi using pip.

502 bad gateway on Ngnix+Gunicorn+Django configuratoin

I am deploying a django webapp on digitalocean and I am using Nginx and Gunicorn.
And when I open my url, it shows 502 bad gateway.
In the nginx_errors.log, I find the following error message:
[error] 12229#0: *1 connect() to unix:/home/demo/webapps/hello/run/gunicorn.sock failed (111: Connection refused) while connecting to upstream, client: 123.45.6.78, server: demohello.com, request: "GET / HTTP/1.1", upstream: "http://unix:/home/demo/webapps/hello/run/gunicorn.sock:/", host: "demohello.com"
Is it because my nginx configuration is wrong? How to fix it?
You need to set the configurations for gunicorn correctly which is in /etc/init/gunicorn.conf.
Be careful with:
--name=django_project \
--pythonpath=django_project \
django_project.wsgi:application

nginx error while trying to serve django page

I'm new at server setup. I'm trying to set up an EC2 instance to serve a Django app through nginx. I'm able to run and connect to the Django app using
python managy.py runserver 0.0.0.0:8000
However, while trying to setup the nginx to serve Django, I get the following error:
2013/05/22 06:19:25 [crit] 10035#0: *8 connect() to
unix:///home/ubuntu/web/something.com/something_uwsgi.sock failed (2:
No such file or directory) while connecting to upstream, client:
50.156.16.40, server: jamsnap.com, request: "GET / HTTP/1.1", upstream:
"uwsgi://unix:///home/ubuntu/web/something.com/something_uwsgi.sock:",
host: "ec2.something.com"
Can anyone point me in the right direction? I'm at a loss right now.

502 error after adding application to a Django project running on nginx and gunicorn

I am trying to add an application to an existing Django project, but once I have done it I get a 502 error.The server is running Ubuntu. I don't think it has to do with the applications code because I got it running on the django development server. It goes away when I take out the app's name from settings.py and restart gunicorn.
Here's a part of the log
2011/07/15 01:24:45 [error] 16136#0: *75593 connect() failed (111: Connection refused) while connecting to upstream, client: 24.17.8.152, server: staging.site.org, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8020/", host: "staging.site.org"
Here's the nginx config file.
Nginx Config File
I'm not sure what other information is needed. Not sure where the gunicorn logs are located. My server admin skills are kind of lacking.
Nginx isn't able to connect to your backend (gunicorn) or gunicorn is refusing the connection. You provided no details about the configuration so that's all the help you'll get. You are correct that the application code has nothing to do with it. It's a configuration error on your part.