Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Redirect to other servers based on FQDN

$
0
0
I belive this is called Reverse Proxying, but heres my situation...

I need to be able to redirect incomming http and https requests, all comming in on the same IP, to other web servers based on FQDN.

After some research onling I found Ngnix and set up a server.

I've tried figuring out how to do this but I can't seem to get it to work.

Example Enviroment

Ngnix Server IP 192.168.1.10
Site1.example.com IP 192.168.1.20
Site2.example.com IP 192.168.1.21

/etc/nginx/sites-enabled/default.conf contents
-----
server {
listen 80;
server_name site1.example.com;
port_in_redirect off;
error_log off;
real_ip_header X-forwarded-For;

location / {
proxy_redirect off;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proy_add_x_forwarded_for;
proxy_pass http://192.168.1.20;
}
}


server {
listen 80;
server_name site2.example.com;
port_in_redirect off;
error_log off;
real_ip_header X-forwarded-For;

location / {
proxy_redirect off;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proy_add_x_forwarded_for;
proxy_pass http://192.168.1.21;
}
}
-----

I got that configuration layout after digging around some with google, not sure if it even does what I want, but I think I at least half understand what is doing after reading the nginx docs.

What I want it to do is take all the requests comming in on 192.168.1.10 and redirect to the apropriat web servers IP, idealy being completly transparent so that eveything works as if there was no middle man and the client where connecting directly to the external web servers.

I'm also looking into what I need to do to amke it work for hte sites that are https. I've noticed more then once ssl confguration options, but not sure if I actualy need to do them when I'm just trying to use Nginx to NAT based on FQDN. Any help reguarding this is welcome.

Thanks for any help in advance

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>