7

I am using gunicorn and trying to write the upstart script. I am testing the command in the command line and for port 80 it just gets errors

command

gunicorn --bind 0.0.0.0:80 --workers 3 myapp.wsgi:application

log

[2016-10-19 02:36:51 +0000] [12752] [INFO] Starting gunicorn 19.6.0
[2016-10-19 02:36:51 +0000] [12752] [ERROR] Retrying in 1 second.
[2016-10-19 02:36:52 +0000] [12752] [ERROR] Retrying in 1 second.
[2016-10-19 02:36:53 +0000] [12752] [ERROR] Retrying in 1 second.
[2016-10-19 02:36:54 +0000] [12752] [ERROR] Retrying in 1 second.
[2016-10-19 02:36:55 +0000] [12752] [ERROR] Retrying in 1 second.
[2016-10-19 02:36:56 +0000] [12752] [ERROR] Can't connect to ('0.0.0.0', 80)

any ideas why this is not working? Sometimes it works for port 8000.

xazb
  • 129
  • 1
  • 1
  • 7
  • 2
    Are you running as root (if running on Linux) (non root in general can't bind to < 1024). is something else (e.g. apache /iis) already running on port 80? – Foon Oct 19 '16 at 02:46
  • 1
    @Foon no nothing is running on port 80. Now its working if I use sudo. I thought you generally do not want to run a webserver with root. – xazb Oct 19 '16 at 02:49
  • 1
    I don't know how gunicorn is setup; I typically start apache httpd via root (as in run service httpd start) but httpd will quickly change user to apache (on RHEL/Fedora; Ubuntu/Debian is similar but slightly different) once it's done the privileged port bind – Foon Oct 19 '16 at 02:54
  • 1
    @Foon gunicorn will run locally then nginx will be a reverse proxy for it. – xazb Oct 19 '16 at 02:59
  • @xazb: Then you do not want gunicorn running on port 80! nginx will be running on port 80. – Kevin Oct 19 '16 at 03:06
  • 1
    If you already have the NginX running that's why Gunicorn can't listen to the same port. Use another port and modify the NginX configuration accordingly. – Selcuk Oct 19 '16 at 03:54
  • I have written detailed anser for this here, without using nginx or any other web server: https://stackoverflow.com/a/61802211/5687711 – im_bhatman May 14 '20 at 17:04

2 Answers2

5

You have to use 'sudo' command for this.

sudo gunicorn --bind 0.0.0.0:80 --workers 3 myapp.wsgi:application

Port 80 requires superuser privilege.

RoboMex
  • 828
  • 12
  • 13
2

If you are on a unix-like environment, ports < 1024 (like 80) will require superuser privileges.

From the question: https://stackoverflow.com/a/16225928/6823310

Originally answered by:

https://stackoverflow.com/users/358328/uku-loskit

This is why port 8000 works and 80 do not.

Try running the command with sudo.

Otherwise check if that port is not already being used by another service.

Santiago M. Quintero
  • 1,237
  • 15
  • 22