LikeApache

= Nginx solution for Apache ProxyPassReverse =

Let's say we want to establish simple proxy between myhost:80 and myapp:8080. The Apache rule is simple:

APACHE

 ServerName myhost DocumentRoot /path/to/myapp/public ProxyPass / http://myapp:8080/ ProxyPassReverse / http://myapp:8080/ 

But Nginx does not have ProxyPassReverse...The solution is adding few missing HTTP headers.


 * 1) Please also see http://wiki.nginx.org/HttpProxyModule#proxy_redirect, This wiki is partly incorrect. If you need to do location header rewriting. You will need to use proxy_redirect as well.

NGINX:

server { listen myhost:80; server_name myhost; location / { root /path/to/myapp/public; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://myapp:8080; } }