Our Blog

Let us find tech solutions together

Feb 06

How to setup a Wicket application with nginx and Jetty

By kinabalu | Comments

 

Our signature sample is our “5 Days Of Wicket” tutorial app MysticPaste.com. And recently I decided to migrate the app from being proxied by Apache to nginx.

We have always backed the pastebin with Jetty and this hasn’t changed. Without further adieu here is our config for nginx:

server {
  listen  80;
  server_name mysticpaste.com www.mysticpaste.com;

  access_log  /var/log/nginx/mysticpaste.com.access.log;

  location / {
    proxy_pass  http://127.0.0.1:8081/mysticpaste/;
    proxy_pass_header Set-Cookie;
    proxy_pass_header X-Forwarded-For;
    proxy_pass_header Host;
  }

}

So far so good. The app does essentially what we want, hosts in Jetty under the context path /mysticpaste while offering it up on the root path via nginx and our users. Under this configuration you’ll see a slight problem however, in that the cookie path isn’t being properly set due to the proxy. In Apache we would just use ProxyPassReverseCookiePath, but this doesn’t appear to be an option in nginx anywhere I could find.

Next best thing, add a context-param to our web.xml and change the SessionPath that Jetty uses to be root instead of /mysticpaste.

    
        org.mortbay.jetty.servlet.SessionPath
        /
    

All works as it did with Apache, and you get some nginx goodness mixed in.