Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Gunicorn use port 8000/8001 instead of 80?

I busy setting up a development environment for Django Framework using Gunicorn (as Django service) and NGINX (as a Reverse Proxy).

When I look at several tutorials like this one and this one, I see that they use port 8000 and port 8001 (http://127.0.0.1:8000 and http://127.0.0.1:8001). Is there a special reason not to use port 80, like any other webserver?

Port 8000 is often used for radio streaming and malware, so why?

BTW: I am running it using Virtualenv on a Ubuntu 12.04 system.

like image 757
Wouter Dorgelo Avatar asked Jul 12 '12 01:07

Wouter Dorgelo


2 Answers

All ports under 1024 are privileged ports. To bind to a privileged port requires root user permissions and typically you don't want to run gunicorn with root level permissions.

What's done instead is to allow nginx to bind to 127.0.0.1:80 and then proxy requests to port 80 to a non-privileged port like 8000 using an nginx configuration like:

server {
        location / {
                proxy_pass http://127.0.0.1:8000;
        }
}
like image 128
dgh Avatar answered Sep 17 '22 22:09

dgh


NGINX listens on port 80 and forwards to Gunicorn. Gunicorn operates on the 127.0.0.1 IP rather than 0.0.0.0, so it isn't listening publicly, and therefore the only way to access the site externally is through port 80.

like image 23
Randall Ma Avatar answered Sep 19 '22 22:09

Randall Ma