Flask服务器从端口5000开始。使用gunicorn和nginx,当我在浏览器中键入http://localhost:80
(或http://localhost
)时,浏览器将重定向到http://localhost:5000
。
我在nginx配置文件中添加了几行
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
重定向后如何隐藏端口(在这种情况下为5000)?非常感谢。
答案 0 :(得分:0)
这是构造配置文件的方式:
server {
# listen on port 80
listen 80;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
服务器块是Nginx配置的子集,它定义了用于处理已定义类型的请求的虚拟服务器。
位置块位于服务器块内,用于定义Nginx应如何处理父服务器对不同资源和URI(域名或IP地址/端口之后的请求部分)的请求>