Reverse Proxy problems

Francis Daly francis at daoine.org
Sat Sep 30 12:50:18 UTC 2017


On Fri, Sep 29, 2017 at 03:17:45PM -0400, redbaritone wrote:

Hi there,

> I am having some problems with my Nginx reverse proxy. I'm running a web
> application on port 8010 that accepts and serves two different web sites
> from that port.

The most likely way that web application does that, is if it selects
which site to serve based on the Host: header in the incoming request.

> name1.domain.com:8010 and name2.domain.com:8010.

> 1: I setup one upstream server and accessed it through proxy_pass from both
> server definitions:
> 
> upstream my_server{
>     server 127.0.0.1:8010;
> }
> 
> server {
>     server_name name1.domain.com;
> 
>     location / {
>        proxy_pass http://my_server;

nginx will send a Host: header of my_server.

> server {
>     server_name name2.domain.com;
> 
>     location / {
>        proxy_pass http://my_server;

nginx will also send a Host: header of my_server.

Your web application will presumably handle those two requests in the same way.

> The second way I tried this was to create a different upstream for each
> website, using the full DNS names for each, and then calling the appropriate
> upstream proxy from each server definition:
> 
> upstream name1_server{
>     server name1.domain.com:8010;
> }
> 
> upstream name2_server{
>    server name2.domain.com:8010;
> }
> 
> ... (the same as above, except replacing my_server with name1/2_server at
> proxy_pass)

nginx will send a Host: header of name1_server or name2_server; your
web application *could* distinguish based on those, but it is probably
configured to distinguish only based on the names name1.domain.com and
name2.domain.com.

> Obviously, I don't understand the relationship between how nginx deals with
> upstream declarations and how that passes along to my web application. Any
> help would be appreciated.

Either use something like "proxy_pass http://name2.domain.com;", or use
your current "proxy_pass" lines but add something like "proxy_set_header
Host name2.domain.com;" -- either of those would have nginx sending a Host
header of name2.domain.com, which is probably what you want.

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list