java – PlayFramework在http而不是httpS中返回绝对URL?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – PlayFramework在http而不是httpS中返回绝对URL?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2980字,纯文字阅读大概需要5分钟。
内容图文
![java – PlayFramework在http而不是httpS中返回绝对URL?](/upload/InfoBanner/zyjiaocheng/759/abf8d019708340ab9900d14e89ff2d98.jpg)
我在仅使用https的NGinx的Play!Framework中实现了一个项目.
一切正常,SSL是公认的,我可以在任何地方使用我的应用程序,但播放时!返回绝对URL,它是http,而不是https.
这是有问题的,我不知道问题出在哪里.
我尝试使用-Dhttps.port = XXXX而不是-Dhttp.port = XXXX启动Play,但它没有更改“http”而不是“https”的输出.
我怀疑Nginx配置错误(我忘记了一个参数?).
这是我的网站启用/网站配置文件:
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme "https"; # I also tried $scheme without any luck
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
server {
listen 80;
server_name my.website.com;
return 301 https://my.website.com;
}
upstream my-backend {
server 127.0.0.1:9100;
}
server {
listen 443;
ssl on;
root /var/www/website/errors/;
# http://www.selfsignedcertificate.com/ is useful for development testing
ssl_certificate /etc/nginx/ssl/my.website.com.crt;
ssl_certificate_key /etc/nginx/ssl/my.website.com.key;
# From https://bettercrypto.org/static/applied-crypto-hardening.pdf
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # not possible to do exclusive
ssl_ciphers 'EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA';
add_header Strict-Transport-Security max-age=15768000; # six months
# use this only if all subdomains support HTTPS!
# add_header Strict-Transport-Security "max-age=15768000; includeSubDomains"
keepalive_timeout 70;
server_name my.website.com;
location / {
#proxy_pass http://my-backend;
proxy_pass http://127.0.0.1:9100;
}
location ~ /\.git {
deny all;
}
error_page 502 @maintenance;
location @maintenance {
rewrite ^(.*)$/error502.html break;
}
}
我错过了什么?
更新:这是生成绝对URL的代码:
controllers.routes.Pages.loginToken(getToken()).absoluteURL(play.mvc.Http.Context.current().request());
解决方法:
absoluteURL有几个重载.你正在使用这个:
public String absoluteURL(Http.Request request) {
return absoluteURL(request.secure(), request.host());
}
这个问题是,由于您通过nginx反向代理播放,Play实际上是通过HTTP接收所有请求,而不是HTTPS.这意味着request.secure()为false,而absoluteURL将返回包含http:// ….的URL.
相反,在其中一个重载中手动将secure设置为true:
controllers.routes.Pages.loginToken(getToken()).absoluteURL(play.mvc.Http.Context.current().request(), true);
此外,我通常做的是安全配置变量,因此它可以在本地开发时生成非https URL.
在application.conf中:
application.secure = false # for local dev
在生产中,我在启动应用程序时添加命令行选项-Dapplication.secure = true,以覆盖application.conf中的值.
然后生成URL将如下所示:
controllers.routes.Pages.loginToken(getToken()).absoluteURL(
play.mvc.Http.Context.current().request(),
play.Play.application().configuration().getBoolean("application.secure", true) // default to true
);
内容总结
以上是互联网集市为您收集整理的java – PlayFramework在http而不是httpS中返回绝对URL?全部内容,希望文章能够帮你解决java – PlayFramework在http而不是httpS中返回绝对URL?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。