我的项目是nginx+spring boot,,弹簧启动端口为8080在我使用nginx转发后,request.getRequestURL()只能得到http而不能得到https
public static String getRootUrl(HttpServletRequest request){
StringBuffer url = request.getRequestURL();
String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append(request.getSession().getServletContext().getContextPath()).append("/").toString();
return tempContextUrl;
}
nginx配置了https
server {
listen 80;
server_name xx.xxx.xx;
add_header Strict-Transport-Security max-age=15768000;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name xx.xxx.xxx;
keepalive_timeout 10m;
ssl_certificate cert.pem; #
ssl_certificate_key cert.key; #
ssl_session_timeout 24h;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
add_header Content-Security-Policy upgrade-insecure-requests;
}
}
你的nginx代理到8080端口,这个应用程序是一个集成的tomcat服务器,你没有在这个tomcat中配置SSL,所以,在应用程序内部,它是http,你可以在spring引导中配置SSL。