【问题标题】:Docker django nginx gunicorn URL dropping portDocker django nginx gunicorn URL 丢弃端口
【发布时间】:2015-03-02 11:09:50
【问题描述】:

首先抱歉,如果这是重复的,但我没有通过 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 配置获取。

我想要实现的是维护 URL 中的端口,以后我可以从主机服务器反向代理。

任何建议将不胜感激。

【问题讨论】:

    标签: django nginx docker gunicorn


    【解决方案1】:

    答案是:

    proxy_set_header Host $http_host;
    

    到打印 hostname:portnumber 的 nginx conf

    在此处查看 serverfault.com 链接:Original thread

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-14
      • 2011-03-24
      • 2019-01-08
      • 2015-04-25
      • 2019-01-04
      • 2020-08-15
      • 1970-01-01
      • 2019-06-01
      相关资源
      最近更新 更多