Welcome! Log In Create A New Profile

Advanced

Reverse Proxy problems

September 29, 2017 03:17PM
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. (As far as I know, there's no way to serve them on different ports, with the server I'm using.) I have different host names for each which are pointed to the same IP address. I'll call them name1.domain.com:8010 and name2.domain.com:8010. Both of these successfully resolve to the appropriate web root within my web application, and the appropriate web site is rendered, IF I include the port number. I want to use Nginx as a reverse proxy however, so that I'll have one place to configure my SSL settings and redirect from old hostnames.

I set up my proxy in nginx two different ways, and neither of them consistently resolve to the right website:

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 {
listen 80;
server_name name1.domain.com;

location / {
root /location_1
proxy_pass http://my_server;
...
}
}

server {
listen 80;
server_name name2.domain.com;

location / {
root /location_2
proxy_pass http://my_server;
...
}
}

Please note that I'm just trying to get the reverse proxy to work. Once I do that, I'll add SSL requirements, and all the necessary rewrites to make sure people are redirected to our secured interface.

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)

Both ways gave the same results. After restarting my web application and nginx (just to make sure I start from a clean slate), both name1.domain.comand name2.domain.com resolve to the name1:domain.com:8010 website. However, if I go to name2.domain.com:8010, then both name1.domain.com and name2.domain.com will resolve to that website. Going to name1.domain.com:8010 then causes both portless addresses to resolve there, until I visit name2.domain.com:8010 directly again.

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.
Subject Author Posted

Reverse Proxy problems

redbaritone September 29, 2017 03:17PM

Re: Reverse Proxy problems

Francis Daly September 30, 2017 08:52AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 213
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