首先道歉,如果这是重复但我没有通过SO
中显示的类似帖子找到解决方案我有一个使用nginx和gunicorn的Docker Django图像。
Gunicorn剧本:
exec /var/www/venv/bin/gunicorn wsgi:application \
--bind 0.0.0.0:8001 \
--access-logfile /var/log/gunicorn/access.log \
--error-logfile /var/log/gunicorn/error.log
Nginx配置:
server {
server_name 172.0.0.1;
access_log off;
location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header Host $host:$server_port;
}
location /static/ {
autoindex on;
alias /var/www/django/assets/;
expires 7d;
}
}
我正在暴露端口80并映射到49260。
当浏览到docker主机外部ip时,包括该站点发布的端口并提供静态文件。
http://xxx.xx.xx.xxx:49260/
问题是当我导航到django站点中的任何其他页面时,映射端口将从URL中删除,然后由主机服务器ngnix config选择。
我想要实现的是维护URL中的端口,以后我可以从主机服务器反向代理。
任何建议都会非常感激。
答案 0 :(得分:2)
答案是补充:
proxy_set_header Host $http_host;
打印主机名:portnumber
的nginx conf请参阅serverfault.com链接:Original thread