Skip to content

Instantly share code, notes, and snippets.

@kuleszaj
Created February 25, 2012 21:48
Show Gist options
  • Save kuleszaj/1911022 to your computer and use it in GitHub Desktop.
Save kuleszaj/1911022 to your computer and use it in GitHub Desktop.
Simple nginx reverse proxy with extra headers.
server {
listen 1.2.3.4:80;
server_name railsapp.example.com;
location / {
proxy_set_header Host $host;
# So the original HTTP Host header is preserved
proxy_set_header X-Real-IP $remote_addr;
# The IP address of the client (which might be a proxy itself)
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# The IP address in the HTTP X-Forwarded-For header (which would be the 'origin' client).
proxy_pass http://rails_application;
}
}
@dhruvsinghal007
Copy link

Can you please provide a working example of this active on a remote location? I want to fetch the remote address on my application through javascript. The application is deployed on the remote host here, and that remote host is proxied by a reverse proxy server (setup through nginx).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment