Welcome! Log In Create A New Profile

Advanced

$domain instead of $host in vhost (for wildcard)

Posted by dirkb 
$domain instead of $host in vhost (for wildcard)
June 16, 2011 05:34PM
in my vhosts file I have
server_name *.com;
root /var/www/$host;


That way all requests that are done for a .com are send to a directory specific for that .com.
However I want to do this per domain and not per host.

The way it's currently it will goto /var/www/myhost.mydomain.com is I use url http://myhost.mydomain.com and to /var/www/www.mydomain.com if I use http://www.mydomain.com.
What I would like is that for http://myhost.mydomain.com and http://www.mydomain.com and http://whatever.mydomain.com it will go to /var/www/mydomain.com

How can this be done?
(we do NOT know upfront what hostname will be used (part before the domainname), also we could have 100s of domainnames, so listing them all individualy within the vhosts file is not an option either)
Re: $domain instead of $host in vhost (for wildcard)
June 19, 2011 12:04PM
Hi -

Try the following:

root /var/www/$http_host;
Re: $domain instead of $host in vhost (for wildcard)
June 22, 2011 02:53AM
Thanks for the answer, however it's not doing what I wanted :-(
Other ideas?
Re: $domain instead of $host in vhost (for wildcard)
July 15, 2011 07:29AM
try:

server_name ~(?<domain>\.[^.]+\.com)$

root /var/www/$domain;


Andrejs
Re: $domain instead of $host in vhost (for wildcard)
July 15, 2011 01:39PM
locojohn Wrote:
-------------------------------------------------------
> try:
>
> server_name ~(?<domain>\.[^.]+\.com)$
>

Sorry:

server_name ~\.(?<domain>[^.]+\.com)$

otherwise, "." before the domain name will be captured into $domain as well. It's easy to mess up with regex :)

Andrejs
Re: $domain instead of $host in vhost (for wildcard)
July 22, 2011 10:56AM
@dirkb - Did this resolve your problem? I believe this is my issue as well, please look at this post:

http://forum.nginx.org/read.php?11,212785

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

Click here to login

Online Users

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