【问题标题】:Location header returned by HTTPFound does not include non-standard port numberHTTPFound 返回的位置标头不包含非标准端口号
【发布时间】:2012-06-17 03:15:03
【问题描述】:

我有一个 Pyramid 应用程序在 nginx(监听端口 8080)后面的 gunicorn(监听 Unix 套接字)上运行。当 Pyramid 视图返回 HTTPFound(location='/') HTTP 响应包含 Location: http://example.host/ 而没有端口号时,用户会收到“无法连接”错误。我不知道在哪里指定非标准端口号,或者(最好)如何告诉 Pyramid 在生成 Location 标头时从请求中提取它。

摘自应用程序配置:

[server:main]
use = egg:gunicorn#main
host = unix:%(here)s/run/server.sock
workers = 4

Nginx 配置:

server {
    listen 8080;
    root /path/to/app;
    location / {
        proxy_pass http://unix:/path/to/app/run/server.sock;
        include proxy_params;
    }
    location /static {
        root /path/to/app/static;
    }
}

【问题讨论】:

    标签: python redirect nginx pyramid gunicorn


    【解决方案1】:

    要获取服务器端口,请使用host_port

    同样根据rfc2616,您确实应该在Location 标头中发送绝对URI 而不是相对URI。

    【讨论】:

    • 谢谢,您的回复将我推向了正确的方向:1) 我用request.route_url 调用替换了location 参数中的硬编码字符串(我的错,'/' 更容易输入比request.route_url('frontpage'))。 2) Nginx proxy_params 包含proxy_set_header Host $host; 但它应该是proxy_set_header Host $http_host;
    • @Burhan:Pyramid 负责为应用程序开发人员生成绝对 URL,因此这里不必担心;缺少的是正确的路由调用和 ngnix 配置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-06
    • 1970-01-01
    • 1970-01-01
    • 2018-04-25
    • 2018-02-18
    • 2018-09-09
    相关资源
    最近更新 更多