# Difficulty configuring virtual host

**URL:** <https://www.ruby-forum.com/t/difficulty-configuring-virtual-host/217741>\
**Category:** NGINX\
**Created:** [March 11, 2012, 1:49am UTC](https://www.ruby-forum.com/t/difficulty-configuring-virtual-host/217741 "2012-03-11T01:49:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 11, 2012, 1:49am UTC](https://www.ruby-forum.com/t/difficulty-configuring-virtual-host/217741/1 "2012-03-11T01:49:51Z")

</div>

good day all I want to configure my virtual hosts based on the srcip of  
the client, so basically the ip of the connecting client determines what  
document root to set.

Any ideas how this can be accomplished?

– Thank you for your time  
– Paul G Webster  
– Checkout Opera M2 @ [Opera Web Browser | Faster, Safer, Smarter | Opera](http://www.opera.com/mail/)

---

<div class="post-metadata">

**Author:** ![Paul\_G\_Webster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b5a626/32.png) [@Paul\_G\_Webster](https://www.ruby-forum.com/u/Paul_G_Webster)\
**Post date:** [March 11, 2012, 1:59am UTC](https://www.ruby-forum.com/t/difficulty-configuring-virtual-host/217741/2 "2012-03-11T01:59:06Z")

</div>

Ideally doing this:

if (srcip == 4.4.4.5) {  
server\_name test1;  
root /usr/local/www/4.4.4.5;  
} elsif (srcip == 2.2.2.2) {  
server\_name test2;  
root /usr/local/www/2.2.2.2;  
}

On Sun, 11 Mar 2012 00:47:54 -0000, Paul G Webster  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–

– Thank you for your time  
– Paul G Webster  
– Checkout Opera M2 @ [Opera Web Browser | Faster, Safer, Smarter | Opera](http://www.opera.com/mail/)

---

<div class="post-metadata">

**Author:** ![Paul\_G\_Webster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b5a626/32.png) [@Paul\_G\_Webster](https://www.ruby-forum.com/u/Paul_G_Webster)\
**Post date:** [March 11, 2012, 2:14am UTC](https://www.ruby-forum.com/t/difficulty-configuring-virtual-host/217741/3 "2012-03-11T02:14:35Z")

</div>

I should probably add as someone just pointed out to me on IRC .. if  
there  
is a way of doing this without ifs I would be more than happy to use it,  
it was an example only 8)

On Sun, 11 Mar 2012 00:57:27 -0000, Paul G Webster  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Sun, 11 Mar 2012 00:47:54 -0000, Paul G Webster
> 
> > – Paul G Webster  
> > – Checkout Opera M2 @ [Opera Web Browser | Faster, Safer, Smarter | Opera](http://www.opera.com/mail/)
> > 
> > * * *
> > 
> > nginx mailing list  
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–

– Thank you for your time  
– Paul G Webster  
– Checkout Opera M2 @ [Opera Web Browser | Faster, Safer, Smarter | Opera](http://www.opera.com/mail/)

---

<div class="post-metadata">

**Author:** ![Paul\_G\_Webster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b5a626/32.png) [@Paul\_G\_Webster](https://www.ruby-forum.com/u/Paul_G_Webster)\
**Post date:** [March 11, 2012, 2:14am UTC](https://www.ruby-forum.com/t/difficulty-configuring-virtual-host/217741/4 "2012-03-11T02:14:36Z")

</div>

On 11 Mar 2012 01h57 CET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ideally doing this:
> 
> if (srcip == 4.4.4.5) {  
> server\_name test1;  
> root /usr/local/www/4.4.4.5;  
> } elsif (srcip == 2.2.2.2) {  
> server\_name test2;  
> root /usr/local/www/2.2.2.2;  
> }

Untested. Using the geo module [1]. At the http level.

geo $root\_dir {  
4.4.4.5 /usr/local/www/4.4.4.5;  
2.2.2.2 /usr/local/www/2.2.2.2;  
}

At the server level (vhost).

server {  
server\_name test1 test2;  
root $root\_dir;  
#…  
}

— appa

[1] [Module ngx\_http\_geo\_module](http://nginx.org/en/docs/http/ngx_http_geo_module.html)

---

<div class="post-metadata">

**Author:** ![Paul\_G\_Webster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b5a626/32.png) [@Paul\_G\_Webster](https://www.ruby-forum.com/u/Paul_G_Webster)\
**Post date:** [March 11, 2012, 2:15am UTC](https://www.ruby-forum.com/t/difficulty-configuring-virtual-host/217741/5 "2012-03-11T02:15:50Z")

</div>

Ahh smart it should work perfectly any way to set the server\_name  
dynamically

On Sun, 11 Mar 2012 01:13:38 -0000, Antnio P. P. Almeida  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > }  
> > server {  
> > nginx mailing list  
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–

– Thank you for your time  
– Paul G Webster  
– Checkout Opera M2 @ [Opera Web Browser | Faster, Safer, Smarter | Opera](http://www.opera.com/mail/)

---

<div class="post-metadata">

**Author:** ![Paul\_G\_Webster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b5a626/32.png) [@Paul\_G\_Webster](https://www.ruby-forum.com/u/Paul_G_Webster)\
**Post date:** [March 11, 2012, 2:33am UTC](https://www.ruby-forum.com/t/difficulty-configuring-virtual-host/217741/6 "2012-03-11T02:33:46Z")

</div>

Works perfectly thank you 🙂

On Sun, 11 Mar 2012 01:13:49 -0000, Paul G Webster  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > if (srcip == 4.4.4.5) {  
> > > 4.4.4.5 /usr/local/www/4.4.4.5;
> > 
> > — appa
> > 
> > [1] [Module ngx\_http\_geo\_module](http://nginx.org/en/docs/http/ngx_http_geo_module.html)
> > 
> > * * *
> > 
> > nginx mailing list  
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–

– Thank you for your time  
– Paul G Webster  
– Checkout Opera M2 @ [Opera Web Browser | Faster, Safer, Smarter | Opera](http://www.opera.com/mail/)
