8

I am running Ubuntu 14.04 instance in my EC2 AWS.

I can run gunicorn -b 0.0.0.0:8000 myapp.wsgi

but it fails to run at port 80

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

I tried to follow this answer (I couldn't understand it though, whats deployment script ?) Getting Gunicorn to run on port 80

But it didn't work.

I also tried running it with elevated permission sudo in vain. Error on running at port 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:

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.
  • What do you mean by it fails? Elaborate more on the error please. – beezz Aug 30 '15 at 16:25
  • @beezz updated answer with error log – Bhrigu Srivastava Aug 30 '15 at 16:38
  • If with `sudo`, error is the same, check if you are not already running something on port 80. Apache or nginx etc. – beezz Aug 30 '15 at 16:40
  • @beezz I ran sudo service nginx stop , but still I can see ngix welcome screen here: http://ec2-54-148-229-51.us-west-2.compute.amazonaws.com – Bhrigu Srivastava Aug 30 '15 at 16:45
  • I uninstalled nginx now , getting a different error with `sudo` (Updating error log in question) – Bhrigu Srivastava Aug 30 '15 at 16:49
  • 2
    Are you sure you want to do this at all? gunicorn isn't really suitable for exposing directly to the internet; usually you'd run it behind a reverse proxy. Since you already had nginx running, you should re-enable it and use it as it is meant to be. – Daniel Roseman Aug 30 '15 at 16:51
  • @DanielRoseman : All I want to do is serve my django application on port 80. I read online while searching `gunicorn` is used widely (Even Heroku uses it for production purposes). I tried basic `./manage.py runserver 0.0.0.0:80 ` and failed. How can I serve my django application with `nginx` on port 80 ? As you might have already guess, I am n00b and trying this for the first time, please bear with me . – Bhrigu Srivastava Aug 30 '15 at 16:58
  • 2
    As I said, you run nginx on port 80, and use it as a reverse proxy in front of gunicorn. Don't try and run gunicorn itself on port 80. The gunicorn docs have a full config example. – Daniel Roseman Aug 30 '15 at 17:12
  • @DanielRoseman Thanks. Got it. – Bhrigu Srivastava Aug 30 '15 at 17:49
  • 1
    http://stackoverflow.com/questions/11443917/why-does-gunicorn-use-port-8000-8001-instead-of-80 – Glyn Jackson Aug 30 '15 at 18:43
  • I'd be very cautious believing that a specific WSGI server is the best just because someone else uses it. What WSGI server is best depends on your specific application. The gunicorn WSGI server with its default sync worker is a poor choice for mostly I/O bound applications especially in memory constrained environments, such as a PaaS, with fat Django web applications. This is because to achieve high concurrency, you need more processes which means more money to the hosting service as you will need to scale out quicker when you run out of memory. For I/O bound, threaded WSGI servers are better. – Graham Dumpleton Aug 30 '15 at 21:48

2 Answers2

0

**It seems that you have not added port 80 to your security groups..

Also you will have to use sudo before your command to access port 80

Hope this helps**

-1

As suggested in comments, its not recommended to run gunicorn on port 80.

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.

This can be done by editing nginx config file.

yask
  • 3,918
  • 4
  • 20
  • 29
  • 6
    This doesn't answer the question. The questioner specifically mentions that he wants gunicorn to run on port 80. Your suggests using nginx as a reverse proxy and then running gunicorn on port 8000. What if we don't want to use nginx or any other reverse proxy server? – GunnerFan May 01 '19 at 05:13