simple reverse web proxy need a little help

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

simple reverse web proxy need a little help

ashuai
I'm new to nginx but needed a solution like this.  It's very cool but I'm a
newbie with a small problem.

I'm using nginx as a simple reverse web proxy.  I have 3 domains on 2
servers.  I'm using 3 files in sites-enabled called your-vhost1.conf ,
your-vhost2.conf and so on.  The stand alone domain is vhost1.  The problem
is, one of the domains on the server that has 2 isn't resolving correctly
from the outside world.  It only resolves correctly when you use just
http://domain.com.  If you use http://www.domain.com it resolves to the
vhost1 domain.   I tried shuffling the vhost1,2, & 3 files to different
domains but that breaks it.  

A bit more info I've got an A record in DNS for WWW  for the domain in
question.  It is hosted on a Windows server with IIS7 and I also have WWW in
site bindings.  This server was standalone before we added the 3rd domain on
the second server.  It did resolve correctly before we added the nginx
server so I'm fairly certain I just don't have the syntax right.  The
standalone server is Debian with a Wordpress site.  Here's the vhost files:

VHOST1 (Standalone)

server {

 server_name domain1.com;

 set $upstream 192.168.7.8;

location / {

proxy_pass_header Authorization;
proxy_pass http://domain1.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_buffering off;
client_max_body_size 0;
proxy_read_timeout 36000s;
proxy_redirect off;

 }
}


VHOST2

server {

 server_name domain2.com;

 set $upstream 192.168.7.254;

location / {

proxy_pass_header Authorization;
proxy_pass http://www.domain2.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_buffering off;
client_max_body_size 0;
proxy_read_timeout 36000s;
proxy_redirect off;

 }
}

VHOST3

server {

 server_name domain3.com;

 set $upstream 192.168.7.254;

location / {

proxy_pass_header Authorization;
proxy_pass http://domain3.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_buffering off;
client_max_body_size 0;
proxy_read_timeout 36000s;
proxy_redirect off;

 }
}

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,277674,277674#msg-277674

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: simple reverse web proxy need a little help

Peter Booth
First Step

Use something like http://www.kloth.net/services/nslookup.php

To check the IP addresses returned for all six names (with and without www for the three domains)

Do these look correct?

Sent from my iPhone

> On Dec 6, 2017, at 5:27 PM, qwazi <[hidden email]> wrote:
>
> I'm new to nginx but needed a solution like this.  It's very cool but I'm a
> newbie with a small problem.
>
> I'm using nginx as a simple reverse web proxy.  I have 3 domains on 2
> servers.  I'm using 3 files in sites-enabled called your-vhost1.conf ,
> your-vhost2.conf and so on.  The stand alone domain is vhost1.  The problem
> is, one of the domains on the server that has 2 isn't resolving correctly
> from the outside world.  It only resolves correctly when you use just
> http://domain.com.  If you use http://www.domain.com it resolves to the
> vhost1 domain.   I tried shuffling the vhost1,2, & 3 files to different
> domains but that breaks it.  
>
> A bit more info I've got an A record in DNS for WWW  for the domain in
> question.  It is hosted on a Windows server with IIS7 and I also have WWW in
> site bindings.  This server was standalone before we added the 3rd domain on
> the second server.  It did resolve correctly before we added the nginx
> server so I'm fairly certain I just don't have the syntax right.  The
> standalone server is Debian with a Wordpress site.  Here's the vhost files:
>
> VHOST1 (Standalone)
>
> server {
>
> server_name domain1.com;
>
> set $upstream 192.168.7.8;
>
> location / {
>
> proxy_pass_header Authorization;
> proxy_pass http://domain1.com;
> proxy_set_header Host $host;
> proxy_set_header X-Real-IP $remote_addr;
> proxy_set_header X-forwarded-For $proxy_add_x_forwarded_for;
> proxy_http_version 1.1;
> proxy_set_header Connection "";
> proxy_buffering off;
> client_max_body_size 0;
> proxy_read_timeout 36000s;
> proxy_redirect off;
>
> }
> }
>
>
> VHOST2
>
> server {
>
> server_name domain2.com;
>
> set $upstream 192.168.7.254;
>
> location / {
>
> proxy_pass_header Authorization;
> proxy_pass http://www.domain2.com;
> proxy_set_header Host $host;
> proxy_set_header X-Real-IP $remote_addr;
> proxy_set_header X-forwarded-For $proxy_add_x_forwarded_for;
> proxy_http_version 1.1;
> proxy_set_header Connection "";
> proxy_buffering off;
> client_max_body_size 0;
> proxy_read_timeout 36000s;
> proxy_redirect off;
>
> }
> }
>
> VHOST3
>
> server {
>
> server_name domain3.com;
>
> set $upstream 192.168.7.254;
>
> location / {
>
> proxy_pass_header Authorization;
> proxy_pass http://domain3.com;
> proxy_set_header Host $host;
> proxy_set_header X-Real-IP $remote_addr;
> proxy_set_header X-forwarded-For $proxy_add_x_forwarded_for;
> proxy_http_version 1.1;
> proxy_set_header Connection "";
> proxy_buffering off;
> client_max_body_size 0;
> proxy_read_timeout 36000s;
> proxy_redirect off;
>
> }
> }
>
> Posted at Nginx Forum: https://forum.nginx.org/read.php?2,277674,277674#msg-277674
>
> _______________________________________________
> nginx mailing list
> [hidden email]
> http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: simple reverse web proxy need a little help

ashuai
I use geopeeker.com to accomplish the same thing only it renders the site so
you can see it, not just resolves the name.

I fixed the problem but I don't think it's the right way to do it.  I
created a 4th conf file for just the WWW and it seems to be working
correctly now.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,277674,277678#msg-277678

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: simple reverse web proxy need a little help

ashuai
I had to go back and create another conf file for the third domain as it was
now directing to the first domain if I use the WWW on it.  
WEIRD!  But creating another conf file works so....unless you want to tell
me I'm doing it wrong, I'll leave it for now.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,277674,277679#msg-277679

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: simple reverse web proxy need a little help

Francis Daly
In reply to this post by ashuai
On Wed, Dec 06, 2017 at 05:27:01PM -0500, qwazi wrote:

Hi there,

> is, one of the domains on the server that has 2 isn't resolving correctly
> from the outside world.  It only resolves correctly when you use just
> http://domain.com.  If you use http://www.domain.com it resolves to the
> vhost1 domain.

Your client does a lookup for whatever name you request, and finds the
IP address to connect to; then it connects to that.

If that IP address corresponds to nginx, then nginx can get involved.

> server {
>  server_name domain1.com;

> server {
>  server_name domain2.com;

> server {
>  server_name domain3.com;

When a request comes to nginx, it will look at all of the server{}
blocks (in this case), and then choose which one to use based on the
server_name setting and the Host header that the client sent -- which
is the name that you want to connect to.

If you use domain2.com, nginx will choose the second one, because
it matches.

If you use www.domain2.com, it does not match any of the server_name
settings that you have, so nginx does not know which server{} to
choose. It chooses its default server{}.

http://nginx.org/r/server_name

Change your nginx config to tell it all of the names that you want each
server{} to handle.

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: simple reverse web proxy need a little help

ashuai
Very cool.  Very simple to understand once you understand it.  I did figure
this out on my own simply by creating more files for the WWW side of each
domain.  It now works properly.  Thank you.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,277674,277695#msg-277695

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx