I think it's a second week started since I'm trying to start the server for Django app, first with Apache, second with gunicorn and now uwsgi + nginx... I'm very thankful for the help on my previous post... nginx with gunicorn and django on centos 7 It pushed me into the right direction...
I don't know why, but most of guides for the django and server are incomplete and don't include settings tuning for the engines like gunicorn and nginx... there are some... and I tried to follow them, but end up with bunch of mistakes. I followed: http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/ and https://youtu.be/DzXCHAuHf0I . Very good guides, but I ended up with the bunch of mistakes, which I'm trying to fix. Any help guys?
Virtual environment installed at: /opt/venv
the way to activate virtual environment at: /opt/venv/sc/bin/activate
Users added for both nginx and uwsgi:
useradd -s /bin/false nginx/uwsgi
nginx.conf:
include /etc/nginx/conf.d/*.conf;
virtual.conf:
server {
listen 80;
server_name site's_ip domain_name;
error_log /srv/www/sc/logs/error.log;
access_log /srv/www/sc/logs/access.log;
charset utf-8;
location /static/ {
alias /srv/www/sc/static/;
}
location /media/ {
alias /srv/www/sc/media/;
}
location / {
uwsgi_pass unix:/opt/uwsgi/sock/sc.sock;
include uwsgi_params;
}
}
emperor.ini:
[uwsgi]
emperor = /etc/uwsgi/vassals
uid = uwsgi
gid = uwsgi
logto = /etc/uwsgi/log
sc.ini:
http = :8000
socket = /opt/uwsgi/sock/sc.sock
chdir = /srv/www/sc
pythonpath = /srv/www/sc/sc
home = /opt/venv/sc
module = sc.wsgi
uid = uwsgi
chmod-socket = 664
chown-socket = uwsgi
uwsgi.service:
[Unit]
Description=uWSGI Emperor
After=syslog.target
[Service]
ExecStart=/opt/venv/sc/bin/uwsgi --ini /etc/uwsgi/emperor.ini
ExecStop = kill -INT 'cat /run/uwsgi.pid'
ExecReload = kill -TERM 'cat /run/uwsgi.pid'
Restart = always
Type = notify
NotifyAccess = main
PIDFile = /run/uwsgi.pid
[Install]
WantedBy=multi-user.target
When I go to the site it shows: 502 Bad Gateway. Although nginx is active and running and uwsgi is active and running.
That is the log for errors, which I have/had:
2020/09/18 08:40:02 [crit] 25458#0: *1 connect() to unix:/opt/uwsgi/sock/sc.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: , request: "GET /whm-server-status HTTP/1.0", upstream: "uwsgi://unix:/opt/uwsgi/sock/sc.sock:"
2020/09/18 08:40:02 [crit] 25458#0: *3 connect() to unix:/opt/uwsgi/sock/sc.sock failed (13: Permission denied) while connecting to upstream, client: , server: , request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/opt/uwsgi/sock/sc.sock:", host: "www...."
2020/09/18 08:40:04 [crit] 25458#0: *3 connect() to unix:/opt/uwsgi/sock/sc.sock failed (13: Permission denied) while connecting to upstream, client: , server: , request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:/opt/uwsgi/sock/sc.sock:", host: "www....", referrer: "http://www..../"
2020/09/18 08:45:44 [crit] 26001#0: *1 connect() to unix:/opt/uwsgi/sock/sc.sock failed (13: Permission denied) while connecting to upstream, client: , server: , request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/opt/uwsgi/sock/sc.sock:", host: "www...."
2020/09/18 08:45:45 [crit] 26001#0: *1 connect() to unix:/opt/uwsgi/sock/sc.sock failed (13: Permission denied) while connecting to upstream, client: , server: , request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:/opt/uwsgi/sock/sc.sock:", host: "www....", referrer: "http://www..../"
2020/09/18 08:45:54 [crit] 26001#0: *5 connect() to unix:/opt/uwsgi/sock/sc.sock failed (13: Permission denied) while connecting to upstream, client: , server: , request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/opt/uwsgi/sock/sc.sock:", host: "www...."
2020/09/18 08:45:54 [crit] 26001#0: *5 connect() to unix:/opt/uwsgi/sock/sc.sock failed (13: Permission denied) while connecting to upstream, client: , server: , request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:/opt/uwsgi/sock/sc.sock:", host: "www....", referrer: "http://www..../"
2020/09/18 08:46:00 [crit] 26001#0: *1 connect() to unix:/opt/uwsgi/sock/sc.sock failed (13: Permission denied) while connecting to upstream, client: , server: , request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/opt/uwsgi/sock/sc.sock:", host: "www...."
2020/09/18 08:46:00 [crit] 26001#0: *1 connect() to unix:/opt/uwsgi/sock/sc.sock failed (13: Permission denied) while connecting to upstream, client: , server: , request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:/opt/uwsgi/sock/sc.sock:", host: "www....", referrer: "http://www..../"
I removed all sites references and ips...
Also if I run systemctl status uwsgi:
Sep 18 09:02:08 systemd[1]: [/etc/systemd/system/uwsgi.service:7] Executable path is not absolute, ignoring: kill -INT 'cat /run/uwsgi.pid'
Sep 18 09:02:08 systemd[1]: [/etc/systemd/system/uwsgi.service:8] Executable path is not absolute, ignoring: kill -TERM 'cat /run/uwsgi.pid'
Sep 18 09:02:08 systemd[1]: Starting uWSGI Emperor...
Sep 18 09:02:08 uwsgi[27421]: [uWSGI] getting INI configuration from /etc/uwsgi/emperor.ini
Sep 18 09:02:08 systemd[1]: Started uWSGI Emperor.
And if I run uwsgi from the command line, I notice it tells following:
[uWSGI] getting INI configuration from /etc/uwsgi/vassals/sc.ini
*** Starting uWSGI 2.0.19.1 (64bit) on [Fri Sep 18 09:10:22 2020] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-39) on 17 September 2020 10:27:10
os: Linux-3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020
nodename:
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /opt/venv/sc/bin
detected binary path: /opt/venv/sc/bin/uwsgi
chdir() to /srv/www/sc
*** WARNING: you are running uWSGI without its master process manager ***
your memory page size is 4096 bytes
detected max file descriptor number: 1048576
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 3
spawned uWSGI http 1 (pid: 27880)
uwsgi socket 0 bound to UNIX address /opt/uwsgi/sock/sc.sock fd 6
setuid() to 985
Python version: 3.6.8 (default, Apr 2 2020, 13:34:55) [GCC (Red Hat )]
PEP 405 virtualenv detected: /opt/venv/sc
Set PythonHome to /opt/venv/sc
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1669d00
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72920 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
added /srv/www/sc/sc/ to pythonpath.
Traceback (most recent call last):
File "./sc/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/opt/venv/sc/lib64/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/opt/venv/sc/lib64/python3.6/site-packages/django/__init__.py",line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/opt/venv/sc/lib64/python3.6/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/opt/venv/sc/lib64/python3.6/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/opt/venv/sc/lib64/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/opt/venv/sc/lib64/python3.6/site-packages/django/contrib/auth/base_user.py", line 48, in <module>
class AbstractBaseUser(models.Model):
File "/opt/venv/sc/lib64/python3.6/site-packages/django/db/models/base.py", line 122, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/opt/venv/sc/lib64/python3.6/site-packages/django/db/models/base.py", line 326, in add_to_class
value.contribute_to_class(cls, name)
File "/opt/venv/sc/lib64/python3.6/site-packages/django/db/models/options.py", line 206, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/opt/venv/sc/lib64/python3.6/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/opt/venv/sc/lib64/python3.6/site-packages/django/db/utils.py",line 214, in __getitem__
backend = load_backend(db['ENGINE'])
File "/opt/venv/sc/lib64/python3.6/site-packages/django/db/utils.py",line 111, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/opt/venv/sc/lib64/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 70, in <module>
check_sqlite_version()
File "/opt/venv/sc/lib64/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 67, in check_sqlite_version
raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 27879, cores: 1)
UPDATE
I tried "chmod 755 uwsgi" like it was explaned in this article: chmod 755 directory_name
And I also tried: chown uwsgi:uwsgi -R uwsgi
I still have faults, but much lesser then I had:
2020/09/18 11:34:52 [crit] 3080#0: *1 connect() to unix:/opt/uwsgi/sock/sc.sock failed (13: Permission denied) while connecting to upstream, client: , server: , request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/opt/uwsgi/sock/sc.sock:", host: ""
2020/09/18 11:35:01 [crit] 3080#0: *4 connect() to unix:/opt/uwsgi/sock/sc.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: , request: "GET /whm-server-status HTTP/1.0", upstream: "uwsgi://unix:/opt/uwsgi/sock/sc.sock:"
2020/09/18 11:35:02 [crit] 3080#0: *6 connect() to unix:/opt/uwsgi/sock/sc.sock failed (13: Permission denied) while connecting to upstream, client: , server: , request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/opt/uwsgi/sock/sc.sock:", host: ""
Update
added chmod command to the opt directory... One more fault is gone... Only two left, but somehow they relate to the same folder which I already gave the permission... It feels that I'm giving wrong permissions?
2020/09/18 11:49:44 [crit] 3833#0: *1 connect() to unix:/opt/uwsgi/sock/sc.sock failed (13: Permission denied) while connecting to upstream, client: , server: , request: "GET / HTTP/1.0", upstream: "uwsgi://unix:/opt/uwsgi/sock/sc.sock:"
2020/09/18 11:49:46 [crit] 3834#0: *3 connect() to unix:/opt/uwsgi/sock/sc.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.0", upstream:"uwsgi://unix:/opt/uwsgi/sock/sc.sock:"
A couple of things I'd recommend as a seasoned uWSGI user (and uWSGI documentation author):
Unless you're planning on hosting a massive number of different services and need to manage them dynamically, don't use the Emperor/Vassal system. Just use a Systemd service per app.
Install uWSGI into the virtualenv your app is in, not system-wide.
If you can trust all of the users on the box your app(s) run on, don't bother with Unix sockets but just use TCP sockets bound on localhost. (If you can't, then UNIX sockets are better with their permission system.)
If possible, give each app their own user instead of sharing a single uwsgi user.
With that in mind, you might adapt from:
uwsgi ini
strict # die on config errors
master # use master process
need-app # die if the app fails to load
die-on-term # obey SIGTERM
socket = 127.0.0.1:50000
chdir = /srv/www/sc/app # or wherever
virtualenv = /opt/venv/sc # or wherever
module = sc.wsgi
nginx configuration
server {
listen 80;
server_name site's_ip domain_name;
error_log /srv/www/sc/logs/error.log;
access_log /srv/www/sc/logs/access.log;
charset utf-8;
location /static/ {
alias /srv/www/sc/static/;
}
location /media/ {
alias /srv/www/sc/media/;
}
location / {
uwsgi_pass 127.0.0.1:50000;
include uwsgi_params;
}
}
systemd unit file
[Unit]
Description=uWSGI for SC app
After=syslog.target
[Service]
ExecStart = /opt/venv/sc/bin/uwsgi --ini that-uwsgi-ini
User = uwsgi
Group = uwsgi
Restart = always
Type = notify
NotifyAccess = main
[Install]
WantedBy=multi-user.target
Related
I'm having issues while setting up nginx and Gunicorn on my local computer (not the server). I have a Django project and I want to be able to access it via http://localhost:8000/. Before my nginx was functional, my Gunicorn server was able to start successfully. However, once I got my nginx server configured, now my Gunicorn server won't start because nginx is already running on my localhost on port 8000. When I visit http://localhost:8000/ I get 500 - Internal Server Error. When I visit http://localhost:80/, however, I get Welcome to nginx! web page.
To configure nginx and Gunicorn, I followed this guide, skipping steps 5 to 7 (inclusive). I have to note that in my /etc/nginx the sites-available and sites-enabled directories didn't exist, so I had to make them.
I have only two files in my /etc/nginx/sites-available directory - default and mydjangoproject. Both have the same contents and both have their symbolic links in /etc/nginx/sites-enabled. Their contents are:
server {
listen 8000;
server_name 127.0.0.1;
location = /favicon.ico { access_log off; log_not_found off; }
location /production_static/ {
root /home/john/Documents/Django_projects/mydjangoproject/Version_2/mydjangoproject;
}
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:8000;
}
}
Here are the relevant parts of my Django project's settings.py file:
DEBUG = False
ALLOWED_HOSTS = ['*', '127.0.0.1', 'localhost']
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'production_static/')
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
MEDIA_URL = '/media/'
STATICFILES_DIRS = [
BASE_DIR / "static",
]
Here is the error log from /var/log/nginx/error.log:
2020/12/20 11:58:09 [emerg] 23584#23584: open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/mydjangoproject:11
2020/12/20 12:01:59 [emerg] 23773#23773: open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/mydjangoproject:11
2020/12/20 12:02:04 [emerg] 23775#23775: open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/mydjangoproject:11
2020/12/20 12:02:05 [emerg] 23777#23777: open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/mydjangoproject:11
2020/12/20 12:12:25 [error] 22879#22879: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "127.0.0.1"
2020/12/20 13:51:08 [error] 22879#22879: *3 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost"
2020/12/20 13:55:01 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:01 [error] 25938#25938: *1 open() "/etc/nginx/html/favicon.ico" failed (2: No such file or directory), client: 127.0.0.1, server: , request: "GET /favicon.ico HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:04 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:21 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:21 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:22 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:55:23 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:56:00 [error] 25938#25938: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8000"
2020/12/20 13:56:48 [warn] 25999#25999: conflicting server name "127.0.0.1" on 0.0.0.0:8000, ignored
2020/12/20 13:57:11 [warn] 26011#26011: conflicting server name "127.0.0.1" on 0.0.0.0:8000, ignored
2020/12/20 13:57:14 [alert] 26013#26013: *1013 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
2020/12/20 13:57:15 [alert] 26013#26013: *2025 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
2020/12/20 13:57:16 [alert] 26013#26013: *3037 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
2020/12/20 13:57:31 [alert] 26013#26013: *4050 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
2020/12/20 14:01:02 [alert] 26013#26013: *5064 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
2020/12/20 14:01:04 [alert] 26013#26013: *6076 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "localhost:8000"
I Googled these errors, but came up with nothing. Can someone tell me why is my nginx displaying 500 - Internal server error and how can I get both Gunicorn and nginx to run on the same address and port (if that's even possible)?
As #iklinac mentions, you cant have two ports config to the same id. The port should be 80 like in the tutorial you mentioned. Not 8000 as you have in the original post.
server {
listen 80;
server_name server_domain_or_IP;
}
Mywebsite.co.uk displays a 502 Error. Running sudo tail -F /var/log/nginx/error.log outputs:
2020/10/22 09:42:13 [warn] 200096#200096: conflicting server name "mywebsite.co.uk" on 0.0.0.0:80, ignored
2020/10/22 09:42:13 [warn] 200107#200107: conflicting server name "mywebsite.co.uk" on 0.0.0.0:80, ignored
2020/10/22 09:42:29 [error] 200110#200110: *1 open() "/home/user/mywebsite-app/static/admin/css/fonts.css" failed (2: No such file or directory), client: 37.70.203.239, server: mywebsite.co.uk, request: "GET /static/admin/css/fonts.css HTTP/1.1", host: "mywebsite.co.uk", referrer: "http://mywebsite.co.uk/"
2020/10/22 09:42:50 [crit] 200110#200110: *4 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 37.70.203.239, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "xxx.xx.xxx.xxx"
2020/10/22 09:42:51 [crit] 200110#200110: *4 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 37.70.203.239, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "xxx.xx.xxx.xxx"
2020/10/22 09:43:00 [error] 200110#200110: *1 open() "/home/user/mywebsite-app/static/admin/css/fonts.css" failed (2: No such file or directory), client: 37.70.203.239, server: mywebsite.co.uk, request: "GET /static/admin/css/fonts.css HTTP/1.1", host: "mywebsite.co.uk", referrer: "http://mywebsite.co.uk/"
2020/10/22 09:43:24 [error] 200110#200110: *1 open() "/home/user/mywebsite-app/static/admin/css/fonts.css" failed (2: No such file or directory), client: 37.70.203.239, server: mywebsite.co.uk, request: "GET /static/admin/css/fonts.css HTTP/1.1", host: "mywebsite.co.uk", referrer: "http://mywebsite.co.uk/"
2020/10/22 09:57:01 [crit] 200110#200110: *10 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 103.42.252.150, server: _, request: "GET / HTTP/1.0", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "xxx.xx.xxx.xxx:80"
2020/10/22 10:07:00 [error] 200110#200110: *12 open() "/home/user/mywebsite-app/static/admin/css/fonts.css" failed (2: No such file or directory), client: 37.70.203.239, server: mywebsite.co.uk, request: "GET /static/admin/css/fonts.css HTTP/1.1", host: "mywebsite.co.uk", referrer: "http://mywebsite.co.uk/"
2020/10/22 10:07:28 [crit] 200110#200110: *15 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 37.70.203.239, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "xxx.xx.xxx.xxx"
I suppose it might have somethint to do with gunicorn.socket being in /etc/systemd/system/gunicorn.socket and not at unix:/home/django/gunicorn.socket? Where do I need to change this? What else might be the problem?
My gunicorn.socket:
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=user
Group=user
EnvironmentFile=/home/user/mywebsite-app/env
WorkingDirectory=/home/user/mywebsite-app
ExecStart=/home/user/env/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
mywebsite-app.wsgi:application
[Install]
WantedBy=multi-user.target
use unix:/run/gunicorn.sock in upstream or proxy_pass not your unix:/home/django/gunicorn.socket
I'm deploying django project using gunicorn and nginx. My nginx setting is,
server {
listen 8000;
server_name 0.0.0.0;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/gagan/saporawebapp;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/gagan/saporawebapp/saporawebapp.sock;
}
}
when i run
sudo nginx -t
It shows that setup is correct . Then i started gunicorn using
gunicorn --daemon --workers 3 --bind unix:/home/gagan/saporawebapp/saporawebapp.sock saporawebapp.wsgi
Then nginx is showing 502 bad gateway. Corresponding error log is,
2019/10/08 07:51:34 [emerg] 3988#3988: open() "/etc/nginx/sites-enabled/saporawebapp" failed (2: No such file or directory) in /etc/nginx/nginx.conf:62
2019/10/08 07:59:54 [crit] 4278#4278: *1 connect() to unix:/home/ubuntu/myproject/myproject.sock failed (2: No such file or directory) while connecting to upstream, client: 42.108.169.252, server: 0.0.0.0, request: "GET /signup/ HTTP/1.1", upstream: "http://unix:/home/ubuntu/myproject/myproject.sock:/signup/", host: "157.245.108.160:8000"
2019/10/08 08:05:19 [crit] 4278#4278: *5 connect() to unix:/home/ubuntu/myproject/myproject.sock failed (2: No such file or directory) while connecting to upstream, client: 42.108.169.252, server: 0.0.0.0, request: "GET /signup/ HTTP/1.1", upstream: "http://unix:/home/ubuntu/myproject/myproject.sock:/signup/", host: "157.245.108.160:8000"
2019/10/08 08:06:24 [crit] 4744#4744: *1 connect() to unix:/home/ubuntu/myproject/myproject.sock failed (2: No such file or directory) while connecting to upstream, client: 42.108.169.252, server: 0.0.0.0, request: "GET /signup/ HTTP/1.1", upstream: "http://unix:/home/ubuntu/myproject/myproject.sock:/signup/", host: "157.245.108.160:8000"
2019/10/08 08:14:47 [alert] 5279#5279: 768 worker_connections are not enough
2019/10/08 08:14:47 [error] 5279#5279: *763 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 157.245.108.160, server: 0.0.0.0, request: "GET /signup/ HTTP/1.0", upstream: "http://157.245.108.160:8000/signup/", host: "157.245.108.160:8000"
2019/10/08 09:49:53 [crit] 11601#11601: *1 connect() to unix:/home/gagan/saporawebapp/saporawebapp.sock failed (2: No such file or directory) while connecting to upstream, client: 42.108.169.252, server: 0.0.0.0, request: "GET / HTTP/1.1", upstream: "http://unix:/home/gagan/saporawebapp/saporawebapp.sock:/", host: "157.245.108.160:8000"
Checked out a few other similar issues here, but can't diagnose the issue.
My site has been occasionally going down with a 502 Bad Gateway Error.
I found the following in my error log. Note i'm using a VPS server on Ubuntu 16.04 using Gunicorn/NGINX.
2017/02/21 01:08:29 [crit] 1247#1247: *1 connect() to unix:/home/django/chrisblog/chrisblog.sock failed (2: No such file or directory) while connecting to upstream, client: 173.48.32.62, server: 45.32.201.31, request: "GET /redditclone/ HTTP/1.1", upstream: "http://unix:/home/django/chrisblog/chrisblog.sock:/redditclone/", host: "pythoncreate.com"
2017/02/21 01:10:36 [crit] 1575#1575: *1 connect() to unix:/home/django/chrisblog/chrisblog.sock failed (2: No such file or directory) while connecting to upstream, client: 173.48.32.62, server: 45.32.201.31, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/chrisblog/chrisblog.sock:/", host: "pythoncreate.com"
2017/02/21 01:48:04 [crit] 2342#2342: *2 connect() to unix:/home/django/chrisblog/chrisblog.sock failed (2: No such file or directory) while connecting to upstream, client: 173.48.32.62, server: 45.32.201.31, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/chrisblog/chrisblog.sock:/", host: "pythoncreate.com"
When i go to check the gunicorn status i get the following so it looks like maybe it is failing for some reason?:
gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2017-02-21 01:46:08 UTC; 7min ago
Main PID: 2245 (code=exited, status=203/EXEC)
Feb 21 01:46:08 mydjangoblog systemd[1]: Started gunicorn daemon.
Feb 21 01:46:08 mydjangoblog systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC
Feb 21 01:46:08 mydjangoblog systemd[1]: gunicorn.service: Unit entered failed state.
Feb 21 01:46:08 mydjangoblog systemd[1]: gunicorn.service: Failed with result 'exit-code'.
And here is a shot of output of ps aux | grep nginx
root 2341 0.0 0.1 125104 1480 ? Ss 01:47 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 2342 0.0 0.4 125444 3152 ? S 01:47 0:00 nginx: worker process
django 2461 0.0 0.2 16576 2000 pts/0 S+ 01:57 0:00 grep --color=auto nginx
any help here is hugely appreciated
You just need to check whether "/home/django/chrisblog/chrisblog.sock" exists.
Setting up a site using nginx and in the error logs it's denied permissions for the sock file.
22017/01/26 08:42:38 [crit] 2362#2362: *1 connect() to unix:///tmp/kb.sock failed (13: Permission denied) while connecting to upstream, client: 197.232.12.165, server: kenyabuzz.nation.news, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///tmp/kb.sock:", host: "kenyabuzz.nation.news"
What would be the optimal chmod rights to set for the sock file?