【问题标题】:(https)Nginx --> (http)Play!. But request.secure is false(https)Nginx --> (http)播放!但是 request.secure 是假的
【发布时间】:2011-06-13 01:22:45
【问题描述】:

在 Play 前将 Nginx 配置为反向代理!并通过 https 设置了以下标题:-

        proxy_set_header   X-Forwarded-Proto https; 
        proxy_set_header   X-Forwarded-Ssl https; 

login() [https://localhost/login] 正在转发到 Play!在港口 9000 作为“http”。但是 login() 中的 request.secure 仍然是“假的”。任何的想法 ?

更新: 这是服务器配置:-

server {
    listen                443;
    server_name           localhost;

    ssl                   on;
    ssl_certificate       /home/aymer/play/key/localhost.crt;
    ssl_certificate_key   /home/aymer/play/key/localhost.key;
    ssl_session_timeout   5m;

    location ~ ^/(images|javascript|js|css|flash|media|static)/  {
            root    /home/aymer/play/playapp/public;
            expires 30d;
    }

    location ~* (login|register)$ { 
            proxy_pass         http://localhost:9000;
            proxy_redirect     off;

            proxy_set_header   Host               $host;
            proxy_set_header   X-Real-IP          $remote_addr;
            proxy_set_header   X-Forwarded-Proto  https;
            proxy_set_header   X-Forwarded-Ssl    on;
        }

    location / {
        rewrite ^/(.*) http://$host/$1 permanent;
    }
}

【问题讨论】:

  • 请显示完整的server {} 配置。

标签: nginx playframework


【解决方案1】:

第二条写错了,应该是:

proxy_set_header   X-Forwarded-Ssl on; 

这样就可以解决问题了

更新:无法测试,我看到的唯一缺少的是这个标题:

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

除此之外,一切似乎都是正确的。

【讨论】:

  • 挖一点 play.mvc.Http.Request 类。除了设置 XFF 标头之外,我还必须在 application.conf 文件中添加 XForwardedSupport=。例如:在我的情况下,XForwardedSupport=127.0.0.1。它现在可以工作了。
  • 注意:Play 2.5似乎忽略了headers,只检查request.uri是否以https开头来设置request.secure
【解决方案2】:

只是为了说清楚。我在这个问题上跑过,很难找到完整的工作解决方案。

要使其正常工作,您的 nginx 配置必须包含:

proxy_set_header   X-Forwarded-Ssl    on;
proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;

参数

proxy_set_header   X-Forwarded-Proto  https;

没用(对于这个用例)。

但您还需要在 application.conf 中指定此内容:

XForwardedSupport=<proxy server address> # generally, 127.0.0.1

这个答案只是对 Pere Villega 和 Aymer 之间整个对话的回顾。

【讨论】:

    【解决方案3】:

    我想解决办法是改变:

    "proxy_redirect     off;" 
    

    进入

    "proxy_redirect     http://localhost https://localhost;"
    

    "localhost" 是 server_name 的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-01
      • 2014-03-14
      • 2017-11-07
      • 1970-01-01
      • 1970-01-01
      • 2014-10-09
      • 2014-05-08
      相关资源
      最近更新 更多