Wouter Dorgelo
Wouter Dorgelo

Reputation: 11978

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.

Upvotes: 6

Views: 10259

Answers (2)

dgh
dgh

Reputation: 9137

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;
        }
}

Upvotes: 19

898247
898247

Reputation: 10606

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.

Upvotes: 1

Related Questions