I’ve been trying to get this Django website deployed for a week. However, I’m brand new to servers, the internet, Django, Nginx, etc. I’m using the Django one-click-image and I have followed all the tutorials, instructions, stackoverflow question etc. I’ve gotten so close to having the settings right, I can taste it.
I can get the html template deployed but it won’t deploy the static files (well, the css or an img) according to many hours on the internet I’m not serving them properly. Some searches i did wanted me to adjust gunicorn.conf… but it doesn’t seem to exist on my image. I’m going to give a lot more info than maybe I should sorry, but there’s a lot of common mistakes and I need you to know I’ve already covered that territory
If I just leave the settings.py to have STATIC_URL = ‘/static/’ my basic html template (a couple of links to other pages in the site and a title that do work) comes up but it will not load the css… or even an image in that folder when I tried that. If I give it any other STATIC related constants I get a 502 Bad Gateway.
Things I put in were like:
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), ‘static’) STATICFILES_DIRS = ( os.path.join(BASE_DIR, ‘static’), )
STATICFILES_FINDERS = ( im not typing all this out)
And every combination thereof.
my urls.py files (I have two) both import settings and include the following after the urlpatterns list: (when the constants are visible in settings):
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
I always run collectstatic and systemctl restart gunicorn.service after any changes.
The latest 502 gateway error produced this in the Nginx log:
2017/12/01 14:00:16 [error] 2151#2151: *1135 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 220.127.116.11, server: _, request: “GET / HTTP/1.1”, upstream: “http://unix:django/unicorn.socket:/”, host: “my ip”
2017/12/02 14:00:18 [error] 2151#2151: *1135 connect() to unix:/home/django/gunicorn.socket failed (111: Connection refused) while connecting to upstream, client: 18.104.22.168, server: _, request: “GET / HTTP/1.1”, upstream: “http://unix:/home/django/gunicorn.socket:/”, host: “my ip”
the first looks like a timeout, but I don’t know. Please let me know if you need more information. I’m tearing my hair out.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
Click below to sign up and get $100 of credit to try our products over 60 days!