I'm proxying request from nginx to Jetty, but I have problem with request that Jetty receives. Jetty requests shows that request IP address is 127.0.0.1. But I want real server IP and my site has multiple domains, so when request is coming from some domain name to my server, it must available in Jetty request too.
nginx config:
server {
listen 80; ## listen for ipv4
listen [::]:80 default ipv6only=on; ## listen for ipv6
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Real-IP $remote_addr;
}
}
Servlet request:
Dump Servlet
getMethod: GET
getContentLength: -1
getContentType: null
getRequestURI: /dump/info
getRequestURL: http://127.0.0.1:8080/dump/info
getContextPath:
getServletPath: /dump
getPathInfo: /info
getPathTranslated: /tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/info
getQueryString: null
getProtocol: HTTP/1.0
getScheme: http
getServerName: 127.0.0.1
getServerPort: 8080
getLocalName: 127.0.0.1
getLocalAddr: 127.0.0.1
getLocalPort: 8080
getRemoteUser: null
getUserPrincipal: null
getRemoteAddr: 127.0.0.1
getRemoteHost: 127.0.0.1
getRemotePort: 50905
getRequestedSessionId: 6ubs42zhm5q61k5hm84ni3ib
isSecure(): false
isUserInRole(admin): false
getLocale: en_US
getLocales: en_US
getLocales: en
Best Answer
If I understand it correctly, you want to proxy requests for multiple domains using one
location
block in nginx.In this situation you can modify your configuration as follows:
That copies Host header from the source request to the proxied request and allows backend server to use virtual hosts.