我一周前在Digitalocean上建立了一个使用django和postgres制作的网站,然后按照django nginx,gunicorn和postgres教程here进行了操作,并使用了数字空间作为我们的静态文件。当我们在生产环境中测试网站时,整个一周的一切运行都很好,一切正常(出于测试原因,将Debug = true保留)。几小时前,在我测试了一些东西之后突然出现了502错误的网关错误。我检查了nginx错误日志,并在此显示错误:
2019/12/23 00:30:00 [错误] 7988#7988:* 2202 recv()失败(104:对等重置连接),同时从上游读取响应头,客户端:125.0.0.1,服务器:www .myapp.com,请求:“ GET / reviews / business / id = 3 / HTTP / 1.1”,上游:“ http://unix:/run/gunicorn.sock:/reviews/business/id=3/”,主机:“ myapp.com”,引荐来源网址:“ https://myapp.com/category/Salon/” 2019/12/23 00:30:12 [错误] 7988#7988:* 2208 connect()到Unix:/run/gunicorn.sock在连接到上游时失败(111:连接被拒绝),客户端:125.0.0.1,服务器:www.myapp.com,请求:“ GET / reviews / business / id = 3 / HTTP / 1.1”,上游:“ http://unix:/run/gunicorn.sock:/reviews/business/id=3/”,主持人:“ myapp.com”,引荐来源网址:“ {{3} }” 2019/12/23 00:30:25 [错误] 7988#7988:* 2212到unix的connect():/ run / gunicorn.sock在连接到上游时失败(111:连接被拒绝),客户端:125.0.0.1,服务器:www.myapp.com,请求:“ GET / HTTP / 1.1”,上游:“ https://plentypot.biz/category/Salon/”,托管:“ myapp.com”
我运行了nginx -t并成功返回,表示配置一切正常
使用命令journalctl -u gunicorn记录gunicorn错误,其输出为:
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 systemd[1]: Started gunicorn daemon.
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: [2019-12-16 13:00:49 +0000] [10979] [INFO] Starting gunicorn 20.0.4
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: [2019-12-16 13:00:49 +0000] [10979] [INFO] Listening at: unix:/run/gunicorn
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: [2019-12-16 13:00:49 +0000] [10979] [INFO] Using worker: sync
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: [2019-12-16 13:00:49 +0000] [10997] [INFO] Booting worker with pid: 10997
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: [2019-12-16 13:00:49 +0000] [10997] [ERROR] Exception in worker process
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: Traceback (most recent call last):
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: File "/home/cybafrican/djangoprojectdir/mydjangoenv/lib/python3.7/site-pa
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: worker.init_process()
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: File "/home/cybafrican/djangoprojectdir/mydjangoenv/lib/python3.7/site-pa
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: self.load_wsgi()
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: File "/home/cybafrican/djangoprojectdir/mydjangoenv/lib/python3.7/site-pa
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: self.wsgi = self.app.wsgi()
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: File "/home/cybafrican/djangoprojectdir/mydjangoenv/lib/python3.7/site-pa
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: self.callable = self.load()
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: File "/home/cybafrican/djangoprojectdir/mydjangoenv/lib/python3.7/site-pa
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: return self.load_wsgiapp()
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: File "/home/cybafrican/djangoprojectdir/mydjangoenv/lib/python3.7/site-pa
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: return util.import_app(self.app_uri)
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: File "/home/cybafrican/djangoprojectdir/mydjangoenv/lib/python3.7/site-pa
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: mod = importlib.import_module(module)
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: File "/home/cybafrican/djangoprojectdir/mydjangoenv/lib/python3.7/importl
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: return _bootstrap._gcd_import(name[level:], package, level)
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: File "<frozen importlib._bootstrap>", line 983, in _find_and_load
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocke
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: ModuleNotFoundError: No module named 'myapp.wsgi'
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: [2019-12-16 13:00:49 +0000] [10997] [INFO] Worker exiting (pid: 10997)
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: [2019-12-16 13:00:49 +0000] [11000] [INFO] Booting worker with pid: 11000
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: [2019-12-16 13:00:49 +0000] [11000] [ERROR] Exception in worker process
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: Traceback (most recent call last):
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: File "/home/cybafrican/djangoprojectdir/mydjangoenv/lib/python3.7/site-pa
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: worker.init_process()
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: File "/home/cybafrican/djangoprojectdir/mydjangoenv/lib/python3.7/site-pa
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: self.load_wsgi()
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: File "/home/cybafrican/djangoprojectdir/mydjangoenv/lib/python3.7/site-pa
Dec 16 13:00:49 ubuntu-s-1vcpu-1gb-nyc3-01 gunicorn[10979]: self.wsgi = self.app.wsgi()
我的gunicron配置文件:
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=cybafrican
Group=www-data
WorkingDirectory=/home/cybafrican/djangoprojectdir
ExecStart=/home/cybafrican/djangoprojectdir/mydjangoenv/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
myapp.wsgi:application
[Install]
WantedBy=multi-user.target
我的项目路径/ home / cybafrican / djangoprojectdir:
└── djangoprojectdir
├── Pages
├── Recommend
├── Responses
├── Templates
├── Users
├── media
├── mydjangoenv
├── myapp
├── profiles
└── static
我在网上浏览了所有内容,但似乎找不到任何帮助 谢谢