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:"