Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-57773

IndexOutOfBound or Redirect loop with Apache reverse proxy and portal.proxy.path setting

    Details

      Description

      Configure a reverse proxy with Apache 2.4.16 with the following configuration:

      <VirtualHost *:80>
          ServerName www.myhost.it
          
          ErrorLog /var/log/httpd/www.myhost.it.error.log
          CustomLog /var/log/httpd/www.myhost.it.access.log combined
      
          ProxyRequests Off
          ProxyPreserveHost On
          ProxyVia On
      
          <Proxy *>
              AddDefaultCharset Off
              Order deny,allow
              Allow from all
          </Proxy>
      
          <location /testpath>
              ProxyPass http://localhost:8080/
              ProxyPassReverse http://localhost:8080/
          </location>
      </VirtualHost>
      

      Configure portal-ext with:

      portal.proxy.path=/testpath
      

      If you are VirtualHostFilter active, probably you will have an IndexOutOfBound Exception, otherwise you will obtain a redirect loop.
      After a lot of debug the problem seems to be in FriendlyURLServlet.getPathInfo(HttpServletRequest request) where it isn't considered the contextpath.
      We resolve on our installation with the following code for the method:

      	protected String getPathInfo(HttpServletRequest request) {
      		String requestURI = request.getRequestURI();
      
      		
      		int pos = requestURI.indexOf(Portal.JSESSIONID);
      
      		if (pos != -1) {
      			requestURI = requestURI.substring(0, pos);
      		}
      
      		if(requestURI.startsWith(StringPool.DOUBLE_SLASH)){
      			requestURI = requestURI.substring(1);
      		}
      		
      		String pathContext = PortalUtil.getPathContext();
      		if(Validator.isNotNull(pathContext)){
      			requestURI = pathContext.concat(requestURI);
      		}
      		
      		return requestURI.substring(_friendlyURLPathPrefix.length());
      	}
      

      We tested this solution with proxy context path and without context path, with VirtualHostFilter and without it.
      All seems work well.
      Some minor problems remain on site administration menu on the dockbar for the administrator and on css/js resource loading, but they can be resolved removing the last slash in the proxy configuration.
      From:

          <location /testpath>
              ProxyPass http://localhost:8080/
              ProxyPassReverse http://localhost:8080/
          </location>
      

      To:

          <location /testpath>
              ProxyPass http://localhost:8080
              ProxyPassReverse http://localhost:8080
          </location>
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              juan.gonzalez Juan Gonzalez (Inactive)
              Reporter:
              l.provenzani@3fconsulting.it Luca Provenzani
              Participants of an Issue:
              Recent user:
              Esther Sanz
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                6 years, 11 weeks ago

                  Packages

                  Version Package
                  6.2.X EE
                  7.0.0 M4