Welcome! Log In Create A New Profile

Advanced

configure /etc/nginx/nginx.conf to redirect to separate host

Posted by sniglet 
configure /etc/nginx/nginx.conf to redirect to separate host
February 22, 2013 06:30PM
Does anyone know how to modify the nginx.conf file to redirect to another host? I would like to direct http://mydomain.com/page1 and http://mydomain.com/page2 to separate hosts on my local network. mydomain.com/page1 should go to 10.100.0.163 and mydomain.com/page2 should go to 10.100.0.164.

Here is what I added to the HTML section of the nginx.conf file on my Ubuntu server.

==================
location /page1/ {
rewrite ^/page1/(.*)$ http://10.100.0.163/$1 permanent;
}

location /page2/ {
rewrite ^/page2/(.*)$ http://10.100.0.164/$1 permanent;
}
==================

Is there anything else I need to add to the nginx.conf file? Are there any other configuration files I also need to modify?

I just did a standard install of nginx and haven't changed anything else.
Re: configure /etc/nginx/nginx.conf to redirect to separate host
February 22, 2013 07:36PM
I have made a little more progress by embedding the location code within a server function. At least I don't get any errors when starting nginx now. But I am still not getting a redirection to my internal web servers.

server {
listen 80;
server_name mydomain.com www.mydomain.com;
root html;

location /page1/ {
rewrite ^/page1/(.*)$ http://10.100.0.163/$1 permanent;
}

location /page2/ {
rewrite ^/page2/(.*)$ http://10.100.0.164/$1 permanent;
}

}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

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