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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.

1
2
3
4
    <context-param>
        <param-name>org.mortbay.jetty.servlet.SessionPath</param-name>
        <param-value>/</param-value>
    </context-param>

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