(https)Nginx - >(http)播放!但是request.secure是假的

13 nginx playframework

在Play前配置Nginx作为反向代理!并通过以下标题集传递https: -

        proxy_set_header   X-Forwarded-Proto https; 
        proxy_set_header   X-Forwarded-Ssl https; 
Run Code Online (Sandbox Code Playgroud)

login()[ https://localhost/login]正在转发给Play!在端口9000上为'http'.但是login()中的request.secure仍然是'false'.任何的想法 ?

更新:这是服务器conf: -

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

Per*_*ega 7

第二个条目是错误的,它应该是:

proxy_set_header   X-Forwarded-Ssl on; 
Run Code Online (Sandbox Code Playgroud)

这将解决问题

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

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Run Code Online (Sandbox Code Playgroud)

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

  • 挖了一下play.mvc.Http.Request类.除了设置XFF头之外,我还必须在application.conf文件中添加XForwardedSupport = <代理服务器地址>.例如:在我的例子中,XForwardedSupport = 127.0.0.1.它现在正在工作. (3认同)