Apache proxy pass in nginx
Posted
by
summerbulb
on Server Fault
See other posts from Server Fault
or by summerbulb
Published on 2012-06-25T10:26:48Z
Indexed on
2012/06/25
15:17 UTC
Read the original article
Hit count: 326
I have the following configuration in Apache:
RewriteEngine On
#APP
ProxyPass /abc/ http://remote.com/abc/
ProxyPassReverse /abc/ http://remote.com/abc/
#APP2
ProxyPass /efg/ http://remote.com/efg/
ProxyPassReverse /efg/ http://remote.com/efg/
I am trying to have the same configuration in nginx. After reading some links, this is what I have :
server {
listen 8081;
server_name localhost;
proxy_redirect http://localhost:8081/ http://remote.com/;
location ^~/abc/ {
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://remote.com/abc/;
}
location ^~/efg/ {
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://remote.com/efg/;
}
}
I already have the following configuration:
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location ^~/myAPP {
alias path/to/app;
index main.html;
}
location ^~/myAPP/images {
alias another/path/to/images
autoindex on;
}
}
The idea here is to overcome a same-origin-policy problem. The main pages are on localhost:8080 but we need ajax calls to http://remote.com/abc. Both domains are under my control.
Using the above configuration, the ajax calls either don't reach the remote server or get cut off because of the cross origin.
The above solution worked in Apache and isn't working in nginx, so I am assuming it's a configuration problem.
I think there is an implicit question here: should I have two server
declarations or should I somehow merge them into one?
EDIT: Added some more information
EDIT2: I've moved all the proxy_pass configuration into the main server
declaration and changed all the ajax calls to go through port 8080. I am now getting a new error: 502 Connection reset by peer
. Wireshark shows packets going out to http://remote.com with a bad IP header checksum.
© Server Fault or respective owner