简体   繁体   English

在 AWS EC2 上部署 django 应用程序时无法在端口 80 上运行 gunicorn

[英]Can't run gunicorn on port 80 while deploying django app on AWS EC2

I am running Ubuntu 14.04 instance in my EC2 AWS.我在我的 EC2 AWS 中运行 Ubuntu 14.04 实例。

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

but it fails to run at port 80但它无法在端口 80 运行

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

I tried to follow this answer (I couldn't understand it though, whats deployment script ?) Getting Gunicorn to run on port 80我试图按照这个答案(虽然我无法理解,什么是部署脚本?) 让 Gunicorn 在端口 80 上运行

But it didn't work.但它没有用。

I also tried running it with elevated permission sudo in vain.我也尝试使用提升的权限sudo运行它,但徒劳无功。 Error on running at port 80:在端口 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)

On running with sudo I get this error:使用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.

As suggested in comments, its not recommended to run gunicorn on port 80 .正如评论中所建议的,不建议在端口80上运行gunicorn

We instead run it on port greater than 1024 (non privileged ports) and by reverse poxy request to port greater than 1014 running on gunicorn .我们改为在大于1024端口(非特权端口)上运行它,并通过反向 poxy 请求到大于1014端口在gunicorn运行。

This can be done by editing nginx config file.这可以通过编辑nginx配置文件来完成。

**It seems that you have not added port 80 to your security groups.. **您似乎没有将端口 80 添加到您的安全组中。

Also you will have to use sudo before your command to access port 80此外,您必须在命令访问端口 80 之前使用sudo

Hope this helps**希望这可以帮助**

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

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