在AWS EC2上部署django app时,无法在端口80上运行gunicorn

时间:2015-08-30 16:00:35

标签: python django amazon-web-services amazon-ec2 gunicorn

我在EC2 AWS中运行Ubuntu 14.04实例。

我可以运行gunicorn -b 0.0.0.0:8000 myapp.wsgi

但它无法在端口80上运行

gunicorn -b 0.0.0.0:80 myapp.wsgi - >失败

我试着按照这个答案(我无法理解,但部署脚本是什么?)Getting Gunicorn to run on port 80

但它不起作用。

我也尝试使用提升权限sudo徒劳地运行它。 在端口80上运行时出错:

ubuntu@ip-172-31-39-159:~/jeequery$ gunicorn -b 0.0.0.0:80 rubiks.wsgi
[2015-08-30 15:58:10 +0000] [6772] [INFO] Starting gunicorn 19.3.0
[2015-08-30 15:58:10 +0000] [6772] [ERROR] Retrying in 1 second.
[2015-08-30 15:58:11 +0000] [6772] [ERROR] Retrying in 1 second.
[2015-08-30 15:58:12 +0000] [6772] [ERROR] Retrying in 1 second.
[2015-08-30 15:58:13 +0000] [6772] [ERROR] Retrying in 1 second.
[2015-08-30 15:58:14 +0000] [6772] [ERROR] Retrying in 1 second.
[2015-08-30 15:58:15 +0000] [6772] [ERROR] Can't connect to ('0.0.0.0', 80)

使用sudo运行时出现此错误:

ubuntu@ip-172-31-39-159:~$ gunicorn -b 0.0.0.0:80 rubiks.wsgi
[2015-08-30 16:48:09 +0000] [6943] [INFO] Starting gunicorn 19.3.0
[2015-08-30 16:48:09 +0000] [6943] [ERROR] Retrying in 1 second.
[2015-08-30 16:48:10 +0000] [6943] [ERROR] Retrying in 1 second.
[2015-08-30 16:48:11 +0000] [6943] [ERROR] Retrying in 1 second.
^C[2015-08-30 16:48:12 +0000] [6943] [ERROR] Retrying in 1 second.
[2015-08-30 16:48:13 +0000] [6943] [ERROR] Retrying in 1 second.
[2015-08-30 16:48:14 +0000] [6943] [ERROR] Can't connect to ('0.0.0.0', 80)
ubuntu@ip-172-31-39-159:~$ ^C
ubuntu@ip-172-31-39-159:~$ sudo gunicorn -b 0.0.0.0:80 rubiks.wsgi
[2015-08-30 16:48:21 +0000] [6947] [INFO] Starting gunicorn 19.3.0
[2015-08-30 16:48:21 +0000] [6947] [INFO] Listening at: http://0.0.0.0:80 (6947)
[2015-08-30 16:48:21 +0000] [6947] [INFO] Using worker: sync
[2015-08-30 16:48:21 +0000] [6950] [INFO] Booting worker with pid: 6950
[2015-08-30 16:48:21 +0000] [6950] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/gunicorn/arbiter.py", line 507, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.4/dist-packages/gunicorn/workers/base.py", line 118, in init_process
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.4/dist-packages/gunicorn/util.py", line 355, in import_app
    __import__(module)
ImportError: No module named 'rubiks'
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/gunicorn/arbiter.py", line 507, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.4/dist-packages/gunicorn/workers/base.py", line 118, in init_process
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.4/dist-packages/gunicorn/util.py", line 355, in import_app
    __import__(module)
ImportError: No module named 'rubiks'
[2015-08-30 16:48:21 +0000] [6950] [INFO] Worker exiting (pid: 6950)
[2015-08-30 16:48:21 +0000] [6947] [INFO] Shutting down: Master
[2015-08-30 16:48:21 +0000] [6947] [INFO] Reason: Worker failed to boot.

2 个答案:

答案 0 :(得分:0)

根据评论中的建议,不建议在端口gunicorn上运行80

我们改为在大于1024(非特权端口)的端口上运行它,并通过反向poxy请求在1014上运行大于gunicorn的端口。

这可以通过编辑nginx配置文件来完成。

答案 1 :(得分:0)

**似乎您尚未将端口80添加到安全组中。

此外,在访问端口80之前,您还必须使用sudo

希望这会有所帮助**