Nginx – proxying ip from nginx to jetty/gwt

gwtip addressjettynginxPROXY

Good morning!

I have nginx setup in front of jetty 6, which is running a GWT application. I am trying to forward the ip address, and all the answers I find on the internet tell me to do this:

proxy_pass http://localhost:8080;
proxy_set_header X-Real-IP  $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

This works just fine, except that jetty's logs don't show the X-Real-IP, they show 127.0.0.1. Also, jetty/GWT has 127.0.0.1 for getThreadLocalRequest().getRemoteAddr(), although I can access the X-Real-IP to get the correct remote IP.

Any ideas how to get the correct remote ip for the jetty logs and also get getThreadLocalRequest().getRemoteAddr() to work correctly?

Thanks!

Best Answer

You should just add forwarded config to your connector in /etc/jetty.xml. Example:

<Call name="addConnector">
    <Arg>
        <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
           <Set name="forwarded">true</Set>

This should work.