Nginx proxy_pass configuration to virtualhost

Hi,

I would like to redirect to an external URL which is hosted as a apache
virtual host.
nginx resolves the host of the url which obviously does little to
resolve to the correct web root on the server.

| server {
server_name localhost;
location / {
proxy_set_header Host $host;
proxy_pass http://www.urlforvirtualhost.com;
}
}
|

The question is how do I allow proxy_pass without nginx resolving the
ip-address of the host?

I have googled but obviously too many search result feature nginx
configuration for virtual hosts.

Any hints would be kindly appreciated.

Lo5t

Hi tim,

Hi,

I would like to redirect to an external URL which is hosted as a
apache
virtual host.

redirect or proxy_pass? correct wording is important here

nginx resolves the host of the url which obviously does little to
resolve to the correct web root on the server.

i dont understand what you mean here. if nginx doesnt resolve a dns-name
how should it know how to deal with it? dns-names are for humans.

The question is how do I allow proxy_pass without nginx resolving the
ip-address of the host?

but why dont you want nginx to resolve the IP?

i’m not sure this will work as expected, except you put in the ip.
but then the apache on the other side should be configred
with the ip in the virtualhost

cheers, mex

Posted at Nginx Forum:

On 21/12/14 11:31, mex wrote:

Hi tim,

Hi,

I would like to redirect to an external URL which is hosted as a
apache
virtual host.
redirect or proxy_pass? correct wording is important here

preferred proxy_pass

nginx resolves the host of the url which obviously does little to
resolve to the correct web root on the server.
i dont understand what you mean here. if nginx doesnt resolve a dns-name
how should it know how to deal with it? dns-names are for humans.
yeah the issue does not seem to be on my side, I have have no issue of
nginx resolving the ip but it seems that the hosting company I would
like to proxy_pass to has the virtual hosts configured on the dns names
The question is how do I allow proxy_pass without nginx resolving the
ip-address of the host?
but why dont you want nginx to resolve the IP?

i’m not sure this will work as expected, except you put in the ip.
but then the apache on the other side should be configred
with the ip in the virtualhost
generally I concur but how would they be able to, in est multiple sites
on the same public ip but differentiate on dns names (this is also
achievable on nginx) with the default directing to nowhere.

this would probably mean proxy_pass to a host configured to serve
multiple pages as following

http http://wiki.nginx.org/NginxHttpCoreModule#http {
index http://wiki.nginx.org/NginxHttpCoreModule#index index
http://wiki.nginx.org/NginxHttpCoreModule#index.html;

server http://wiki.nginx.org/NginxHttpCoreModule#server {
server_name
http://wiki.nginx.org/NginxHttpCoreModule#server_name
www.domain1.com;
access_log http://wiki.nginx.org/NginxHttpLogModule#access_log
logs/domain1.access.log main;

 root  <http://wiki.nginx.org/NginxHttpCoreModule#root> 

/var/www/domain1.com/htdocs;
}

server http://wiki.nginx.org/NginxHttpCoreModule#server {
server_name
http://wiki.nginx.org/NginxHttpCoreModule#server_name
www.domain2.com;
access_log http://wiki.nginx.org/NginxHttpLogModule#access_log
logs/domain2.access.log main;

 root  <http://wiki.nginx.org/NginxHttpCoreModule#root> 

/var/www/domain2.com/htdocs;
}
}

would not work. I presumed there was a option to force nginx to not
resolve but I can see now this is probably not the case and I would need
to change to redirect instead of proxy_pass.

On Sat, Dec 20, 2014 at 11:36:24PM +0100, Tim Spencer | Spacesharing
GmbH wrote:

Hi there,

I would like to redirect to an external URL which is hosted as a
apache virtual host.

There may be subtleties about your configuration that have not been
included; but I’m not seeing any obvious reason why just changing one
line should not cause it all to work for you…

        location / {
                proxy_set_header Host $host;

Change that to be

proxy_set_header Host www.urlforvirtualhost.com;

and test again.

                proxy_pass http://www.urlforvirtualhost.com;
        }

The question is how do I allow proxy_pass without nginx resolving
the ip-address of the host?

That question is not very clear to me, I’m afraid.

If the above change is insufficient (and it does include assumptions
such as: you will know when the IP address of the upstream
www.urlforvirtualhost.com changes and will restart nginx then), then it
may be helpful for you to describe what you want to happen, in terms of
what machine makes what request to what other machine.

Good luck with it,

f

Francis D. [email protected]