gunicorn worker 无法启动,导致 502 Bad Gateway 错误

gunicorn worker 无法启动,导致 502 Bad Gateway 错误

我正在使用 nginx 1.14.0 和 gunicorn 运行 django 应用程序,我的虚拟机是 Ubuntu 18.04.5。

从今天早上开始,当我尝试访问我的网站时,每个页面都会显示 502 bad gateway 错误。昨天就已经不时显示该页面,重新加载页面即可解决问题。

登录后,我收到以下消息:

System information disabled due to load higher than 1.0

然后当我这样做landscape-sysinfo

System load:  9.05              Processes:           120
  Usage of /:   80.6% of 7.69GB   Users logged in:     1
  Memory usage: 34%               IP address for eth0: xxx.xxx.xxx.xxx
  Swap usage:   0%

这是我尝试访问该网站的任何页面时遇到的错误:

2020/11/06 11:18:40 [error] 981#981: *33 recv() failed (104: Connection reset by peer) while reading response header from upstream, 

在 gunicorn 中:

Traceback (most recent call last):
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/arbiter.py", line 209, in run
    self.sleep()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/arbiter.py", line 357, in sleep
    ready = select.select([self.PIPE[0]], [], [], 1.0)
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
    self.reap_workers()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
    raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/exo/bin/gunicorn", line 11, in <module>
    sys.exit(run())
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 58, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/app/base.py", line 228, in run
    super().run()
 File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/app/base.py", line 72, in run
    Arbiter(self).run()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/arbiter.py", line 229, in run
    self.halt(reason=inst.reason, exit_status=inst.exit_status)
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/arbiter.py", line 342, in halt
    self.stop()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/arbiter.py", line 393, in stop
    time.sleep(0.1)
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
    self.reap_workers()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
    raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

我是 nginx 新手,因此我不太清楚如何解释这些信息以及如何采取行动。在我搞砸事情之前,非常欢迎提出建议!

干杯!

更新:使用 手动运行 gunicorn --debug-log debug,我得到以下回溯:

Traceback (most recent call last):
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/workers/ggevent.py", line 162, in init_process
    super().init_process()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
    self.load_wsgi()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
    return self.load_wsgiapp()
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
    mod = importlib.import_module(module)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'inventory4'

Inventory4 是我的 django 目录,其中包含 settings.py 和 wsgi.py

这非常奇怪,因为我没有对我的项目配置做任何修改。

它在 django:settings.py 中的样子如下:

WSGI_APPLICATION = 'inventory4.wsgi.application'

和 wsgi.py

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'inventory4.settings')

application = get_wsgi_application()

这是我在 /etc/supervisor/conf.d/gunicorn.conf 中配置的内容:

directory=/home/ubuntu/exostocksaas
command=/home/ubuntu/exo/bin/gunicorn  --config /home/ubuntu/exo/lib/python3.6/site-packages/gunicorn/config.py --log-level debug --bind unix:/home/ubuntu/exostocksaas/app.sock inventory4.wsgi:application

autostart=true
autorestart=true
stderr_logfile=/var/log/gunicorn/gunicorn.err.log
stdout_logfile=/var/log/gunicorn/gunicorn.out.log


[group:guni]
programs:gunicorn

我不知道是什么原因导致了这个错误发生以及如何解决它

相关内容