Django site 504 time out on nginx - django

We have django 1.1.1 website, that works fine on development server (python manage.py runserver). But when we use nginx + wsgi, ngnix is timed out and return "504 Gateway is time out". error.log is empty.
So, probably it is environment issue but I don't know where to start because it was working fine and now its not and I have no error to point me in the right direction. Restarting nginx doesn`t help.
I'm new enough to this environment, could someone possible give me some idea of how I could find the problem
Thanks,
Derek

You can try setting DEBUG = True in settings.py and see if you can review the errors.
If that doesn't work, set DEBUG back to False try setting up the ADMINS so you receive emails with the error reports.
Those are my only suggestions at the moment. Good luck.

Look at the error logs for the Nginx server. My guess is that it's invoking something through FCGI or WSGI (whatever you had set up), but that it's not responding correctly. More detail should be in those logs.

It turned out to be mistake in the middleware configuration ... fixed it and all back to normal.

Related

Server Error (500) Django App on AWS server

Good day,
i have currently my django project running on an aws server. I have used Nginx and configured it all. The application is running, but when i try to login via the login page i have created or try to login via the admin panel it gives me a Server Error (500). I have my DEBUG=False and added my server dns to ALLOWED_HOSTS. As for the Database. I have got my SQL Database running on an Azure server and used environment variables (that i have permanently set in my ubuntu terminal) to get my password and username.
I have also tried to set DEBUG to False and trying to figure out the issue when running python manage.py runserver so i could experiment with it on my localhost, but no luck. I cant access 127.0.0.1 eventhough i have added it to my Allowed hosts.
How could i see what the error is? Thank you in advance
Ok, so fixed it!
After each change, you simply run the command sudo supervisorctl reload in your powershell after you ssh'ed into your aws ec2 server.
As for seeing what the error is, simply set DEBUG=True

Debug =True didn't work on production site

I have a project deployed on production with gunicorn and nginx (may be info about environment will help to answer on my question). While building some new functionality i want to see full errors traceback. In settings.py i switched debug=True also i have specified ALLOWED_HOSTS=['host.com','ip_adress'] but this mode isn't work. I expect that when i open 404 page i should see traceback.
I know that enabling debug to true on production isn't a good way. But i need it.
You need to restart your gunicorn socket after making such changes:
sudo systemctl restart yourgunicornsocket

Django runserver giving a 301 error

I'm trying to setup a development version of a Django site (developed by someone else) so that I can make edits and test before putting changes live. I'm getting a HTTP 301 error when I try going into 127.0.0.1:8000.
I've tried other ports to ensure I'm not already using it.
I believe the settings should allow me to run this app, for example I've got:
DEBUG = True
ALLOWED_HOSTS = ['*']
The live site is running from HTTPS so I figure there is something within settings.py which is specifying SSL but I cannot find anything.
Two questions:
Is there any way to emulate HTTPS using runserver?
If not, what should I be looking for which might be forcing HTTPS?
I never managed to get this running using runserver. In the end I set it up on a apache server and it ran fine

Django CMS Deployment issues using Apphooks with Postgresql

I am trying to run a Django CMS project that i created recently. The project uses PostgreSQL for its database, and works great with the runserver command.
But i started having intermittent Bad Gateway(Nginx) issues when i deployed the project using NGINX and WSGI. This error was sometimes happening on the whole site or sometimes in the sidebar where the pages, administration, etc would show up or sometimes in the page or advanced page settings.
The error i was getting was as follows:
django.db.utils.OperationalError: SSL error: decryption failed or bad record mac
So i decided to get into the details of the error and found out that this error occurs only when i am using AppHooks in the project and that too only with PostgreSql. The project worked well when i deployed it using Sqlite database.
I further tried to resolve the issue by setting ssl = false in the config. file of PostgreSql to see if that would change anything. It changed the error i was getting earlier as follows:
django.db.utils.InterfaceError: connection already closed
So i was wondering the reason behind this issue? Let me remind you that this error is happening only when the project is deployed and not when runserver is being used.
UPDATE:
I tried using the Django-debug-toolbar to check what sql queries are being executed during these errors and it turns out the app is working fine. Somehow the debug toolbar is slowing down the applications which is not breaking the app any more. What might be the reason for the app to not work? How can i get around this issue

bitnami django, solution to restarting service?

Hey I use installed bitnami django 1.3.0,
but whenever I add changes to urls.py or views.py in my system due to some error. The error won't disappear after refresh.
I have to restart my bitnami Service, "stop" and then "start" it, which is time consuming, I feel like I'm coding C# apps in visual studio. Sometimes even that doesn't work, I have to sometimes restart my computer and then I suddenly realize "oh wow, the error is solved now!"
Any solution to this? Why does everything require a runserver / restart?
You can use Apache for deploy your application in production but use the Django server for development. You will need to configure your application for being served by apache later (modifying the settings.py and the apache configuration file) but during the development you won't need to restart the server for every change.
Everything requires a restart because of the way that the python process operates. It does not reload the file when it's changed (outside of runserver..which is an anomaly, and just there for convenience)
Python execution isn't like PHP execution in that way, and your code isn't dynamically loaded on every page refresh, it's loaded on every server restart.
Hope that helps.