Reputation:
I get a 502 Bad Request error after deployment with nginx.
I am using a digitalocean droplet.
Everything works fine locally, so I must have missed something while bringing over the files to filezilla...?
sudo journalctl -u gunicorn>
No journal files were found.
sudo tail -30 /var/log/nginx/error.log
2019/07/29 13:42:25 [crit] 1666#1666: *2 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 138.68.234.34, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "myi.pad.dress"
2019/07/29 13:42:30 [crit] 1666#1666: *4 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 46.114.6.201, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "myi.pad.dress"
2019/07/29 13:42:30 [crit] 1666#1666: *6 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 46.114.6.201, server: _, request: "GET /favicon.ico HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/favicon.ico", host: "myi.pad.dress", referrer: "http://myi.pad.dress/"
2019/07/29 13:50:00 [error] 1666#1666: *8 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 46.114.6.201, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "myi.pad.dress"
2019/07/29 13:55:50 [crit] 1666#1666: *10 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 46.114.6.201, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "myi.pad.dress"
2019/07/29 13:57:18 [crit] 1666#1666: *12 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 46.114.6.201, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "myi.pad.dress"
2019/07/29 14:02:23 [crit] 1666#1666: *14 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 46.114.6.201, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "myi.pad.dress"
2019/07/29 14:02:51 [error] 1666#1666: *16 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 46.114.6.201, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "myi.pad.dress"
2019/07/29 14:09:55 [crit] 1666#1666: *18 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 46.114.6.201, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "myi.pad.dress"
2019/07/29 14:09:59 [crit] 1666#1666: *20 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 46.114.6.201, server: _, request: "GET /favicon.ico HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/favicon.ico", host: "myi.pad.dress", referrer: "http://myi.pad.dress/"
2019/07/29 14:15:18 [crit] 1666#1666: *22 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 46.114.6.201, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "myi.pad.dress"
2019/07/29 14:19:58 [crit] 1666#1666: *24 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 46.114.6.201, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "myi.pad.dress"
2019/07/29 14:21:00 [crit] 1666#1666: *26 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 46.114.6.201, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "myi.pad.dress"
sudo systemctl status gunicorn.socket
Unit gunicorn.socket could not be found.
pip freeze
asn1crypto==0.24.0
cryptography==2.1.4
Django==1.11.11
django-crispy-forms==1.7.2
enum34==1.1.6
gevent==1.2.2
greenlet==0.4.12
gunicorn==19.7.1
idna==2.6
ipaddress==1.0.17
keyring==10.6.0
keyrings.alt==3.0
netifaces==0.10.4
psycopg2==2.7.4
pycrypto==2.6.1
pygobject==3.26.1
PyICU==1.9.8
pytz==2018.3
pyxdg==0.25
SecretStorage==2.3.1
six==1.11.0
sqlparse==0.2.4
virtualenv==15.1.0
/home/django/django_project# nano /etc/nginx/sites-available/django
upstream app_server {
server unix:/home/django/gunicorn.socket fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size 4G;
server_name _;
keepalive_timeout 5;
# Your Django project's media files - amend as required
location /media {
alias /home/django/django_project/django_project/media;
}
# your Django project's static files - amend as required
location /static {
alias /home/django/django_project/django_project/static;
}
# Proxy the static assests for the Django Admin panel
location /static/admin {
alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
proxy_buffering off;
proxy_pass http://app_server;
}
}
settings.py
import os
import netifaces
def ip_addresses():
ip_list = []
for interface in netifaces.interfaces():
addrs = netifaces.ifaddresses(interface)
for x in (netifaces.AF_INET, netifaces.AF_INET6):
if x in addrs:
ip_list.append(addrs[x][0]['addr'])
return ip_list
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = 'abc'
DEBUG = True
ALLOWED_HOSTS = ['myipaddress']
INSTALLED_APPS = (
'users',
'blog',
'crispy_forms',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'django_project.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'django_project.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
STATIC_ROOT = '/home/django/django_project/django_project/static'
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
MEDIA_URL = '/media/'
CRISPY_TEMPLATE_PACK = 'bootstrap4'
LOGIN_REDIRECT_URL = 'blog-home'
LOGIN_URL = 'login'
Thank you for any help
Upvotes: 0
Views: 1659
Reputation: 489
sudo journalctl -u gunicorn>
No journal files were found
If your gunicorn.service files are not configured, the service is probably not running. You need to set up a service for gunicorn for the server to start, and nginx has a socket to read. I use the tutorial below for my OS, you can see something compatible for yours, most all steps are similar and have the same purpose.
Upvotes: 0