Welcome! Log In Create A New Profile

Advanced

proxy_pass to a virtual host

Posted by prodigy_ 
proxy_pass to a virtual host
April 26, 2012 04:02AM
A portion of nginx.conf:

server {
listen 80;
server_name site2.example.com;

access_log /var/log/nginx/access.log;

location / {
proxy_pass http://site1.example.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}

Unfortunately, when I try to access site2.example.com, nginx doesn't proxy to site1 URI. Instead it proxies to the IP address site1.example.com resolves to (or at least so it seems). Since site1 is a virtual host I get IIS welcome screen instead of site1 main page.

Any solution?



Edited 1 time(s). Last edit at 04/26/2012 04:03AM by prodigy_.
Re: proxy_pass to a virtual host
April 26, 2012 02:39PM
I would check the DNS records for both first,

dig A site1.example.com
dig A site2.example.com

I assume site1 is not local to the nginx server?
Re: proxy_pass to a virtual host
April 27, 2012 12:49AM
Resolving works for both hosts if you mean this. And yes, site 1 isn't local, it's on IIS on another server.

Also it works with server_name site1.example.com; and proxy_pass http://$host$uri; but this isn't exactly what I wanted to achieve.
Re: proxy_pass to a virtual host
April 27, 2012 03:38AM
What I mean is resolve it on the nginx box itself, I've seen it many times that people override entries with /etc/hosts tricks. Your nginx is supposed to look there first. But thats quite an interesting point you make there. I'm still not convinced it's not a resolving issue now.

How about trying it as such:

under http:

upstream ie_daemon {
server site1.example.com:80;
# [... up to the number of instance, or more, if you want to be free to add more ...]
}

Then under server (keep your server_name)

location / {
proxy_pass http://ie_daemon;

# include /etc/nginx/proxy.conf;
# my system doesn't have the proxy.conf file so I needed to add the following two lines to get redirects working:
proxy_redirect default;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Remember, check resolving from inside and outside the server network to be sure it all matches up. I learned to always check the basics over and over again, saves me so much time.

Good luck
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 119
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready