Lighttpd + Jetty

Last modified by Vincent Massol on 2017/09/10 17:35

I used lighttpd, but I assume it can be done with other webservers too. This is the configuration I used in the lighttpd config (note that my xwiki folder has been moved to /usr/share/jetty/webapps/root (no 'xwiki' at all)):

$HTTP["host"] =~ "^www\.domain\.com$" {
  # ensure all requests for .gwtrpc files go through to java server
  # we can put this rule first as a higher priority, which java couldn't do
  $HTTP["url"] =~ "\.gwtrpc$" {
    proxy.server = ( "" => (( "host" => "127.0.0.1", "port" => 8080 )))
  }
  # otherwise, we can handle the static resources
  else $HTTP["url"] =~ "^/resources/" {
    alias.url       += ( "/resources" => "/usr/share/jetty/webapps/root/resources" )
  }
  # otherwise, we can handle the static resources
  else $HTTP["url"] =~ "^/skins/" {
    alias.url       += ( "/skins" => "/usr/share/jetty/webapps/root/skins" )
  }
  # and here is the primary server
  else $HTTP["host"] =~ "^www\.domain\.com$" {
    proxy.server = ( "" => (( "host" => "127.0.0.1", "port" => 8080 )))
  }
}
# redirect anything.domain.com to www.domain.com
else $HTTP["host"] =~ "\.domain\.com$" {
  url.redirect = ( "^/(.*)" => "http://www.domain.com/$1" )
  server.name                 = "www.domain.com"
}
# redirect domain.com to www.domain.com
else $HTTP["host"] =~ "domain\.com$" {
  url.redirect = ( "^/(.*)" => "http://www.domain.com/$1" )
  server.name                 = "www.domain.com"
}

So lighttpd will serve any static content unless it has .gwtrpc on the end of the URL.

If you use Nginx as a web-server, just add three more locations and set root to them. By try_files Nginx checks static content presence and if doesn't exist, redirect it to the Tomcat  (we expect dynamic content in this case, including all *.gwtrpc requests).

   location /skins/ {
       
root  /var/lib/tomcat7/webapps/ROOT;
    
}

    
location /resources/ {
       
try_files $uri $uri/ @fallback;
       
root  /var/lib/tomcat7/webapps/ROOT;
       
}

    
location @fallback {
       
proxy_pass http://localhost:8080;
     
}

In the example above XWiki installed as ROOT application in Tomcat. Change path to your XWiki application accordingly.

Then in web.xml, I changed the gwtrpc mapping to:

<servlet-mapping>
   <servlet-name>gwtrpc</servlet-name>
   <url-pattern>/resources/*</url-pattern>
   <url-pattern>/skins/*</url-pattern>
 </servlet-mapping>

Since we are using a url-pattern of /path/, it will be specific enough to be a higher priority than the / pattern we'll use next. And since the only thing that will come through via resources or skins will be gwtrpc, then we can be sure it's ok. Note that only resources is required, but I did both anyway.

Now, as described above, add a rule to catch everything else and redirect it to your XWiki servlet:

<servlet-mapping>
   <servlet-name>action</servlet-name>
   <url-pattern>/*</url-pattern>
 </servlet-mapping>

Get Connected