My site looks fine on my Mac and my Windows laptop (using chrome to access homepage https://inspidered.org), but if I try any other devices, I get a 502 gateway error
from nginx.
Nginx is the front end server running as a reverse proxy on digital ocean droplet, with uwsgi
behind it running django 3.1.
Here are my relevant config files:
My debugging tips come from this page: https://digitalocean.com/community/questions/502-bad-gateway-nginx-2
sudo tail -30 /var/log/nginx/error.log
...
2021/03/01 17:45:47 [crit] 16656#0: *3420 connect() to unix:/run/uwsgi/inspidered.lock failed
(2: No such file or directory) while connecting to upstream,
client: 23.100.xxx.yyy,
server: inspidered.org,
request: "GET / HTTP/1.1",
upstream: "uwsgi://unix:/run/uwsgi/inspidered.lock:",
host: "inspidered.org"
nginx has no obvious errors:
sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Also, nginx serves two other servers on the droplet (a python2 cherrypy and a python3 cherrypy) without any problems. Only this uwsgi/django site is affected. And only some devices.
[~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2021-03-01 05:05:21 UTC; 13h ago
Process: 16653 ExecReload=/bin/kill -s HUP $MAINPID (code=exited, status=0/SUCCESS)
Process: 16399 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 16395 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 16394 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 16402 (nginx)
CGroup: /system.slice/nginx.service
├─16402 nginx: master process /usr/sbin/nginx
├─16655 nginx: worker process
└─16656 nginx: worker process
Mar 01 05:05:21 centos-divining systemd[1]: Stopped The nginx HTTP and reverse proxy server.
Mar 01 05:05:21 centos-divining systemd[1]: Starting The nginx HTTP and reverse proxy server...
Mar 01 05:05:21 centos-divining nginx[16395]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Mar 01 05:05:21 centos-divining nginx[16395]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Mar 01 05:05:21 centos-divining systemd[1]: Started The nginx HTTP and reverse proxy server.
Mar 01 05:18:09 centos-divining systemd[1]: Reloading The nginx HTTP and reverse proxy server.
Mar 01 05:18:09 centos-divining systemd[1]: Reloaded The nginx HTTP and reverse proxy server.
I checked and I have no special domain filters on my Mac:
sudo nano /private/etc/hosts
sudo nano /etc/hosts
my uwsgi .service settings
[Unit]
Description=uWSGI Emperor service
[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown nfsnobody:nfsnobody /run/uwsgi'
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites --logger file:logfile=/var/log/uwsgi.log,maxsize=500000
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target
and inspidered.ini
settings
[uwsgi]
project = inspidered
uid = root
base = /root/webapps/insp
chdir = %(base)/%(project)
home = %(base)
module = %(project).wsgi:application
master = true
processes = 5
socket = /run/uwsgi/%(project).sock
chown-socket = %(uid):root
chmod-socket = 666
vacuum = true
logto = /var/log/uwsgi.log
and finally, the emperor is governing 0 vassals
-- which seems like an error, but perhaps they're just living in an autonomous collective
.
[root@centos-divining log]# systemctl status uwsgi.service
● uwsgi.service - uWSGI Emperor service
Loaded: loaded (/etc/systemd/system/uwsgi.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2021-03-01 18:51:10 UTC; 5min ago
Process: 30019 ExecStartPre=/bin/bash -c mkdir -p /run/uwsgi; chown nfsnobody:nfsnobody /run/uwsgi (code=exited, status=0/SUCCESS)
Main PID: 30022 (uwsgi)
Status: "The Emperor is governing 0 vassals"
CGroup: /system.slice/uwsgi.service
├─30022 /usr/local/bin/uwsgi --emperor /etc/uwsgi/sites --logger file:logfile=/var/log/uwsgi.log,maxsize=500000
└─30050 /usr/local/bin/uwsgi --emperor /etc/uwsgi/sites --logger file:logfile=/var/log/uwsgi.log,maxsize=500000
Mar 01 18:51:10 centos-divining systemd[1]: uwsgi.service holdoff time over, scheduling restart.
Mar 01 18:51:10 centos-divining systemd[1]: Stopped uWSGI Emperor service.
Mar 01 18:51:10 centos-divining systemd[1]: Starting uWSGI Emperor service...
Mar 01 18:51:10 centos-divining systemd[1]: Started uWSGI Emperor service.
Mar 01 18:51:24 centos-divining uwsgi[30022]: Mon Mar 1 18:51:24 2021 - logsize: 18446744073709551615, triggering rotation to /var/log/...24684...
Mar 01 18:51:38 centos-divining uwsgi[30022]: Mon Mar 1 18:51:38 2021 - logsize: 18446744073709551615, triggering rotation to /var/log/...24698...
Hint: Some lines were ellipsized, use -l to show in full.
Amazingly, after 2 days of trying everything else, simply forcing a redirect from http to https for all requests coming into the nginx
reverse proxy solved the 502 bad gateway on phones and tablets:
The lessson: chrome is smart
and forces https on any typed in urls, but older phones and kindle fire typed urls still default to http, and my http config was not set up correctly. So I just did this:
server {
listen 80;
listen [::]:80;
server_name inspidered.org inspidered.com;
return 301 https://$host$request_uri;
}