简体   繁体   English

nginx > uwsgi > django 上的错误网关 (502),但只有一个部分设备

[英]Bad Gateway (502) on nginx > uwsgi > django, but only one SOME devices

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.我的网站在我的 Mac 和 Windows 笔记本电脑上看起来很好(使用 chrome 访问主页https://inspidered.org ),但是如果我尝试任何其他设备,我会从 ZEE434023CF640D7DFDB241F6 收到502 gateway error Nginx is the front end server running as a reverse proxy on digital ocean droplet, with uwsgi behind it running django 3.1. Nginx 是在数字海洋水滴上作为反向代理运行的前端服务器,后面的uwsgi运行 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我的调试技巧来自这个页面: 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: nginx 没有明显错误:

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.此外,nginx 为 droplet 上的另外两个服务器(python2 cherrypy 和 python3 cherrypy)提供服务,没有任何问题。 Only this uwsgi/django site is affected.只有这个 uwsgi/django 站点受到影响。 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:我检查了一下,我的 Mac 上没有特殊的域过滤器:

sudo nano /private/etc/hosts
sudo nano /etc/hosts

my uwsgi.service settings我的 uwsgi.service 设置

[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 settingsinspidered.ini设置


[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 .最后, emperor is governing 0 vassals ——这似乎是一个错误,但也许他们只是生活在一个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:令人惊讶的是,在尝试了 2 天后,只需强制将所有请求从 http 重定向到 https,即可针对所有进入nginx的请求进行重定向,反向代理解决了手机和平板电脑上的错误网关问题:502

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.教训:chrome 很smart ,可以在任何输入的 url 上强制使用 https,但旧手机和 kindle fire 类型的 url 仍然默认为 http,而我的 Z80791B3AE7002CB88C246876D9FA 设置不正确。 So I just did this:所以我只是这样做了:

    server {
        listen 80;
        listen [::]:80;

        server_name inspidered.org inspidered.com;
        return 301 https://$host$request_uri;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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