Getting Gunicorn to run on port 80

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


Try putting authbind inside your deployment script, e.g.:

mkdir .log 2> /dev/null
DEBUG=0 authbind gunicorn -b 0.0.0.0:80 backend:app --access-logfile .log/access.log --error-logfile .log/general.log

Then just run ./deployment.run 80.

(Also, your script doesn't seem to be using any parameters; perhaps replace 80 in your script with $1?)


You can use authbind to achieve this. Install authbind

sudo apt-get install authbind

Then use auth bind to modify port 80 to make sure that port 80 can be used by non-superusers (aka without superuser privileges). Here are the three commands you can use to achieve this.

sudo touch /etc/authbind/byport/80
sudo chmod 500 /etc/authbind/byport/80
sudo chown USER /etc/authbind/byport/80

USER - can be any user on your system like bhatman or ubuntu or ec2-user.

NOTE: just change 80 to any desired port and it will work for any port. Use this responsibly my friend. :)

Now your gunicorn command will look something like this:

authbind gunicorn -c gunicorn.conf wsgi:app

Just append authbind before your gunicorn command

BONUS: If you are using some command before the gunicorn like newrelic etc, then you need to add --deep flag after authbind

authbind --deep newrelic-admin run-program gunicorn -c gunicorn.conf wsgi:app

for more info about authbind checkout its ubuntu manpage: here

But before running these commands blindly I would suggest you to read the following points.

  1. Gunicorn is an appplication server and is not meant to serve the request directly there it is better to use it behind a web server like Nginx or AWS ALB etc.
  2. Ports less than 1024 are privileged ports and should not be opened or used just like that, you should have a strong reason to run applications on such ports.

NGINX is not a necessity for gunicorn, you can use any web server. Your architecture should always look something like this.

WEB SERVER (NGINX, AWS ALB etc) -> APPLICATION SERVER (Gunicorn, uWsgi etc) -> Application (Flask, Django etc)

Hope this helps you.