Welcome! Log In Create A New Profile

Advanced

RegEx VHost name and the default VHost

January 23, 2013 01:37PM
Hello!

VHost names with RegEx is an absolutely imazing feature of nginx. I llllllllllllllove it! :) But now I've got an issue with it.

On my VM I have a VHost templates ax-common-vhost and use it for VHsots like project.area.loc, so the server_name rule is:

server_name ~^(.*)\.(.*)\.loc$;

It works fine and has already saved much time for me. But the default VHost seems to get a trouble with my template. When a site, that uses it, is active, the default VHost also is trieng to use the template.

Example:

/etc/nginx/sites-available:
> default
-- root /usr/share/nginx/html
-- server_name localhost;
> test.sandbox.loc
-- include /etc/nginx/sites-available/ax-common-vhost;
> ax-common-vhost
-- server_name ~^(.*)\.(.*)\.loc$;
-- if ($host ~ ^(.*)\.(.*)\.loc$) {
set $project $1;
set $area $2;

set $folder "$area/$project";
set $domain "$project.$area.loc";
}
-- root /var/www/$folder/;
-- test.sandbox.loc (based on the ax-common-vhost)

/etc/nginx/sites-enabled:
> default
> test.sandbox.loc

By access to the server default VHost (over IP of the VM) an error occures:

2013/01/23 18:41:19 [error] 4051#0: *1 directory index of "/var/www//" is forbidden, client: 192.168.56.1, server: ~^(.*)\.(.*)\.loc$, request: "GET / HTTP/1.1", host: "192.168.56.101"

When I change the server root rule in the template e.g. to /var/www/ and place a test file (index.html) into my webroot folder, it is displayed.

That means: Nginx uses my template for the default host. But "192.168.56.101" cannot be mached to "^(.*)\.(.*)\.loc$"! Is it a bug?
Subject Author Posted

RegEx VHost name and the default VHost

automatix January 23, 2013 01:37PM

Re: RegEx VHost name and the default VHost

Valentin V. Bartenev January 23, 2013 02:18PM

Re: RegEx VHost name and the default VHost

automatix January 23, 2013 02:41PM

Re: RegEx VHost name and the default VHost

Valentin V. Bartenev January 23, 2013 03:24PM

Re: RegEx VHost name and the default VHost

automatix January 23, 2013 03:54PM

Re: RegEx VHost name and the default VHost

Valentin V. Bartenev January 23, 2013 05:32PM

[resolved] Re: RegEx VHost name and the default VHost

automatix January 23, 2013 06:05PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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