Welcome! Log In Create A New Profile

Advanced

How do I match these urls and redirect them to virtual machines ?

Posted by ngxbz 
How do I match these urls and redirect them to virtual machines ?
May 31, 2012 07:30AM
I'm planning to host a webservice for several users with a "common IP".
It the old school way, I would install a apache server, and give users a login_name.
Eventually, they webdata will be seen via http://www.test.com/~abc or http://www.test.com/~def

Now, I planned to allow users to install their virtual machines and run their own apache server.
The only thing I have to do is to run an nginx and redirecting the requests.

Let say, I have a IP and domain called www.test.com
Under this IP, I have a subnet with a pool of machines. Users are allow to install their OS in the form of virtual machines.
Since I have only one IP, the web-clients cannot access to the servers, unless I redirecting the requests by nginx.

if user "abc" and user "def" are running their webservices on 192.168.0.100:80 and 192.168.0.101:80, respectively.
I would like to add two rules for nginx, such that http://www.test.com/abc and http://www.test.com/def go to 192.168.0.100:80 and 192.168.0.101:80, respectively. What would the configuration be look like ?

I have tried
location /abc {
proxy_pass 192.168.0.100:80
}
location /def {
proxy_pass 192.168.0.101:80
}
However, it seem that the nginx were directed to 192.168.0.100:80/a.

Thanks!
Re: How do I match these urls and redirect them to virtual machines ?
May 31, 2012 08:52AM
I have making a little progress.
This is what I'm having in the configuration file

location ~ ^/(?<user>[^/]+)/(?<uri>.+)$ {
echo $user;
echo $uri;
}

the url www.test.com/a/b?=1
gives me $user='b'
and
uri=b

Is there any way I can get the full uri with post args such b?=1 ?

thanks!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

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