This is my first time installing nginx. I install it on my Debian
5.0.3 VPS and use Debian’s repository to install it (version: 0.6.32).
I’m having problem with using regular expression at server_name.
Here’s my configuration:
server {
listen 80;
server_name ~^(.+).mydomain.com$;
location / {
root /home/$1/public_html;
index index.html index.htm;
}
}
When I hit myusername.mydomain.com, where
/home/myusername/public_html/ is exist. It gives me a 404 error. And
when I view the log file, seems like $1 is null or something.
2010/10/14 10:47:08 [error] 4924#0: *3 “/home//public_html/index.html”
is not found (2: No such file or directory), client: 173.245.73.113,
server: ~^(.+).mydomain.com$, request: “GET / HTTP/1.1”, host:
“myusername.mydomain.com”
Am I doing wrong?
Any helps will be appreciated, thanks in advance.
On Thu, Oct 14, 2010 at 05:56:34PM +0700, Indra S. wrote:
server_name ~^(.+).mydomain.com$;
2010/10/14 10:47:08 [error] 4924#0: *3 “/home//public_html/index.html”
is not found (2: No such file or directory), client: 173.245.73.113,
server: ~^(.+).mydomain.com$, request: “GET / HTTP/1.1”, host:
“myusername.mydomain.com”
Am I doing wrong?
Any helps will be appreciated, thanks in advance.
Changes with nginx 0.7.44:
…
*) Bugfix: if there is the single server for given address:port
pair,
then captures in regular expressions in a “server_name” directive
did not work.
…
Adding another server listening on the same socket should resolve
the issue, though I would recommend to upgrade. 0.6.* branch is
legacy and not supported, and you are using an old version from
this branch.
Additionally, it’s really bad idea to use enumerated captures in
server_name. Things may be screwed up easily - it’s enough to add
another regexp to config (e.g. regexp location) to break anything.
There are two possible safe aproaches:
Use named captures as available in nginx 0.8.25+.
server {
server_name ~^(P.+).mydomain.com$;
root /home/$name/public_html;
…
}
On Thu, Oct 14, 2010 at 04:51:05PM +0400, Maxim D. wrote:
[…]
Adding another server listening on the same socket should resolve
the issue, though I would recommend to upgrade. 0.6.* branch is
legacy and not supported, and you are using an old version from
this branch.
Ah, as António pointed out - 0.6.* don’t have server_name
captures at all, so the only options is upgrade or use “if”
matching.
According to http://nginx.org/en/docs/http/server_names.html you need
version >= 0.7.40 in order to use regex with capturing groups in
server_name. Apart from that your config seems correct.