简体   繁体   中英

Uploading django app to digitalocean server: 502 bad gateway nginx/1.4.6 (Ubuntu)

I'm using the following tutorial to upload a django webapp to a digital ocean server. Everything seems fine while entering the following commands:

pip install --upgrade django
service gunicorn restart

According to the tutorial I now should be able to see my webpage (without the bootstrap theme/fonts) after refreshing the host ip in my browser. Instead I get the following error:

在此处输入图片说明

I've looked up the nginx error.log in /var/log/nginx/error.log and it says the following:

2017/01/20 08:18:23 [error] 9342#0: *38 recv() failed (104: 
Connection reset by peer) while reading response header from 
upstream, client: 92.111.75.86, server: _, request: "GET / HTTP/1.1", 
upstream: "http://127.0.0.1:9000/", host: "104.236.68.12"

Question: How do I fix this 502 bad gateway so that my site works properly? I've tried to add ALLOWED_HOSTS = ['104.236.68.12'] to settings.py already and I've also tried to create a droplet with ubuntu 16.04 as well.

You should add the IP address of your DigitalOcean droplet to the ALLOWED_HOSTS variable in your Django settings. Starting from your nginx log, I would set:

ALLOWED_HOSTS = ['104.236.68.12']

PS: Consider to adopt Docker for the deployment of your django app

I'm so sorry guys. This solved the issue...

Dragging my django app in filezilla to

home/django/django_project

instead of:

home/django/django_project/django_project

Basically wasn't precise enough when reading the tutorial, so sorry!

Good day: In the settings.py exactly in ALLOWED_HOSTS = ['*']

This will make it collect all the ips.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM