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

China☆狼群 提交于 2019-12-07 09:57:03

问题


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.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/11443917/why-does-gunicorn-use-port-8000-8001-instead-of-80

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!