欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

nginx代理https后应用程序将https重定向为http--并希望然后jetty request.getScheme fetch https(8和9有区别,8我只是稍微修改了代码)

最编程 2024-07-16 11:20:57
...

不改可参考:https://dev.eclipse.org/mhonarc/lists/jetty-users/msg05430.html

jetty9里start.ini添加配置,具体再看jetty-http-forwarded.xml


--module=http-forwarded

 

nginx 配置参考

server {
listen 443 ssl;
server_name welife.gh.com;
charset utf-8;
ssl_session_timeout 5m;

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;
ssl_certificate /usr/local/nginx/ssl/ssl_20160512/gh.com/gh.com.pem;
ssl_certificate_key /usr/local/nginx/ssl/ssl_20160512/gh.com/gh.com.key;

 
location / {
limit_except GET POST HEAD OPTIONS {
deny all;
}
proxy_pass http://welife-cluster;
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_next_upstream error invalid_header http_503 http_500 http_502 http_504;
proxy_set_header Whatis-Scheme $scheme;

}
}

jetty8.1.18源码修改点

//void org.eclipse.jetty.server.Response.sendError(int code, String message) throws IOException
//非法字符导致请求错误修改

//String uri= request.getRequestURI();
 //shenwr  end 2015-11-20
 String uri=null;
 try{
     uri= request.getRequestURI();
 }catch(NotUtf8Exception e){
     uri=request.getRequestURIISO8859();
 }
 
//shenwr  end 2015-11-20
//String org.eclipse.jetty.server.Request.getRequestURIISO8859()  //add非法字符导致请求错误

public String getRequestURIISO8859()
{
 
    if (_requestURI == null && _uri != null)
        _requestURI = _uri.getPathAndParamISO8859();
    return _requestURI;
 
}

//String org.eclipse.jetty.http.HttpURI.getPathAndParamISO8859() //add 非法字符导致请求错误
public String getPathAndParamISO8859()
 
 {
     if (_path==_query)
         return null;
     return StringUtil.toString(_raw,_path,_param-_path,StringUtil.__ISO_8859_1);
 }

//void org.eclipse.jetty.server.nio.SelectChannelConnector.customize(EndPoint endpoint, Request request) throws IOException


public void customize(EndPoint endpoint, Request request) throws IOException
 
   {
 
       //add by xxxx
       if (request.getHeader("Whatis-Scheme") != null && request.getHeader("Whatis-Scheme").equals("https")) {
           request.setScheme("https");
       } else {
           request.setScheme("http");
       }
 
       //add by xxxx
       request.setTimeStamp(System.currentTimeMillis());
       endpoint.setMaxIdleTime(_maxIdleTime);
       super.customize(endpoint, request);
 
   }
 

 

推荐阅读