The Getrequesturl method for Web HttpServletRequest does not get the HTTPS protocol request issue

Source: Internet
Author: User
Tags tomcat tomcat server

Problem Description:

Use interceptors Intercepter intercept requests in SPRINGMVC, use httpservletrequest in interceptors to get the requested path intercepted (without the path of the request parameter), but the problem is that the path of the requested HTTPS protocol, The program gets the HTTP protocol, resulting in an error in the logic behind it.

Cause Analysis:

Due to the project design to SSO single sign-on function, the use of the Nginx proxy, the entire project is deployed using Nginx+tomcat, so Tomcat received requests from nginx forward, so this problem is caused by nginx configuration problem

Workaround:

1. Add Proxy_set_header x-forwarded-schema $schema at the nginx configuration location; This way, the real path can be obtained by Servlet.getheader ("X-forwarded-schema").
2. In Tomcat Server.xml, add the following

<engine name= "Catalina" defaulthost= "localhost" >  
      <valve classname= " Org.apache.catalina.valves.RemoteIpValve "  
        remoteipheader=" x-forwarded-for "  
        protocolheader=" X-forwarded-proto "  
        protocolheaderhttpsvalue=" https "/> 
...

3. If the Request.getschema () method is used in multiple places in the code, you can modify the tomcat configuration directly to avoid multiple modifications

<connector port= "443" maxhttpheadersize= "8192" maxthreads= "enablelookups=" "
                 false" Disableuploadtimeout= "true"
                 acceptcount= "scheme=" "https" secure= "true"
                 sslenabled= "true"
                 Sslcertificatefile= "${CATALINA.BASE}/CONF/LOCALHOST.CRT"
                 sslcertificatekeyfile= "${catalina.base}/conf/ Localhost.key "/>

If Nginx adds SSL authentication and Tomcat does not add SSL authentication, configure Scheme= "https" secure= "true" one line
If Tomcat also adds SSL authentication, add the configuration

Sslenabled= "true"
sslcertificatefile= "${catalina.base}/conf/localhost.crt"
sslcertificatekeyfile= "${ Catalina.base}/conf/localhost.key "

Can

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.