Error with config when upgrading from 0.6.34 to 0.7.59 (the "alias" directive must use captures insi

I got an error

the “alias” directive must use captures inside location given by regular
expression in /etc/nginx/sites-enabled/default:70

Quite a confusing message for me. The line in question.

alias /home/$homedir/public_html/;

which comes from

For requests starting with a tilde, break them into three components:

1. The username, everything after the tilde up to the first slash

2. The file location, everything after the username up to the last

slash

3. The trailing slash(es)

Then, rewrite to go to the f~/ branch.

location /~ {
if ($request_uri ~ ^/~([^/])(/.[^/]|)(/)$) {
set $homedir $1;
set $filedir $2;
set $trailingslashes $3;
rewrite ^/~([^/]
)(/|$)(.*)$ f~/$3;
}
}

Here, the user-directory components have been parsed. Use an alias to

set

the file directory prefix. But if the file at the requested URI is a

directory, we jump to the ~/ branch for additional processing.

location f~/ {
alias /home/$homedir/public_html/;
if (-d /home/$homedir/public_html$filedir) {
rewrite ^f~/(.*) ~/$1;
}
}

Here, the request is for a directory in a user’s home directory. We

check

that the request URI contained trailing slashes. If it did not, then

we

add the slashes and send a redirect. This circumvents Nginx’s faulty

internal slash-adding mechanism.

location ~/ {
autoindex on;
alias /home/$homedir/public_html/;
if ($trailingslashes = “”) {
rewrite .* /~$homedir$filedir/ redirect;
}
}

(this code comes from this blog SbF₅)

Any ideas what this new error means. Seems related to a “new” feature
added in 0.7.40.

Best Regards

Jools

On Thu, Jun 18, 2009 at 5:37 AM, Jools W.[email protected] wrote:

    set $trailingslashes $3;
  if (-d /home/$homedir/public_html$filedir) {
location ~/ {
added in 0.7.40.

Best Regards

Jools

Try this

or if you prefer the old way, try this instead:

On Thu, 2009-06-18 at 09:33 +0700, Edho P Arief wrote:

Try this

nginx/mod_userdir: take 3 | myconan/blog

or if you prefer the old way, try this instead:

nginx and userdir | myconan/blog

I’ll take a look thanks. Understanding why I can no longer use the code
as before though would still be helpful.

Also, setting up a userdir sholdnt be this complicated. The lack of
multiple conditionals and other aspects to the config can be very
limiting :confused: I think the takeup on NGINX would be more if it was an
easier upgrade route where you could do things without spending hours
working out how to make a config for something that was “easy” on
apache.

Best Regards

Jools

On Wed, Jun 17, 2009 at 11:37:58PM +0100, Jools W. wrote:

    set $trailingslashes $3;
if (-d /home/$homedir/public_html$filedir) {

location ~/ {
added in 0.7.40.
You should use just:

locaiton ~ ^/~([^/]+)(/?.*)$) {
alias /home/$1/public_html/$2;
autoindex on;
}

2009/6/18 Igor S. [email protected]:

    set $homedir $1;
location f~/ {

add the slashes and send a redirect. This circumvents Nginx’s faulty

Any ideas what this new error means. Seems related to a “new” feature
added in 0.7.40.

You should use just:

 locaiton ~ ^/~([^/]+)(/?.)$) {
location ~ ^/~([^/]+)(/?.
)$

why use (/?.) ?
wouldn’t ^/~([^/]+)(.
)$ work as well?

   alias /home/$1/public_html/$2;

is there behavior difference between
alias /home/$1/public_html/$2;
and
alias /home/$1/public_html$2;
?

   autoindex on;
 }

In the page I linked there’s also block for php (which can’t be
handled using alias).

2009/6/18 Igor S. [email protected]:

On Thu, Jun 18, 2009 at 03:13:43PM +0700, Edho P Arief wrote:

is there behavior difference between
alias /home/$1/public_html/$2;
and
alias /home/$1/public_html$2;
?

Yes, you are right.

and that is…?

On Thu, Jun 18, 2009 at 1:43 PM, Jools W.[email protected] wrote:

I’ll take a look thanks. Understanding why I can no longer use the code
as before though would still be helpful.

Also, setting up a userdir sholdnt be this complicated. The lack of
multiple conditionals and other aspects to the config can be very
limiting :confused: I think the takeup on NGINX would be more if it was an
easier upgrade route where you could do things without spending hours
working out how to make a config for something that was “easy” on
apache.

IMO nginx is not suited (or not designed) for multiple user usage.

WRT the alias, it’s either bug or just as intended (I also hit this
error when trying this).

On Thu, Jun 18, 2009 at 03:39:53PM +0700, Edho P Arief wrote:

and that is…?

No significant difference, but

alias /home/$1/public_html$2;

is better.

On Thu, Jun 18, 2009 at 03:13:43PM +0700, Edho P Arief wrote:

alias /home/$homedir/public_html/;
š š if ($request_uri ~ ^/~([^/])(/.[^/]|)(/*)$) {

directory, we jump to the ~/ branch for additional processing.

we
(this code comes from this blog SbF₅)
wouldn’t ^/~([^/]+)(.*)$ work as well?
Probably, your regex will be enough.

š š šalias /home/$1/public_html/$2;

is there behavior difference between
alias /home/$1/public_html/$2;
and
alias /home/$1/public_html$2;
?

Yes, you are right.

š š šautoindex on;
š}

In the page I linked there’s also block for php (which can’t be
handled using alias).

Yes, php handling should more complex.

On Thu, 2009-06-18 at 11:41 +0400, Igor S. wrote:

You should use just:

locaiton ~ ^/~([^/]+)(/?.*)$) {
alias /home/$1/public_html/$2;
autoindex on;
}

will this work since the $homedir part was set in an earlier location.

or you are saying this is a replacement for all the blocks of code I had
before ?

Best Regards

Jools

On Thu, 2009-06-18 at 14:09 +0700, Edho P Arief wrote:

IMO nginx is not suited (or not designed) for multiple user usage.

i have a system with just a few users with some homedirectories
(no php in home area). so because I have more than 1 single site, I
should not use nginx? Reasons I needed nginx were due to lousy apache
performance. Perhaps NGINX should support such setups better. Lighttpd
is of course available, but i had read good things about nginx (and the
performance has been very impressive)

WRT the alias, it’s either bug or just as intended (I also hit this
error when trying this).

the lack of documentation when functionality has changed is a bit of an
issue. this used to work, now it doesnt. Would be great if it said that
somewhere. I realise there are some language barriers, but there are
enough users of NGINX now that things like this need to be addressed.

Best Regards

Jools

On Thu, 2009-06-18 at 11:41 +0400, Igor S. wrote:

locaiton ~ ^/~([^/]+)(/?.)$) { (i changed to location ~ ^/~([^/]+)(/?.)$ {)
alias /home/$1/public_html/$2;
autoindex on;
}

this works well thanks. Are there any security risks with this? For
example could it be abused to gain access to another folder by using a
specific path ?

Best regards

Jools

On Sat, Jun 20, 2009 at 04:27:58PM +0100, Jools W. wrote:

On Thu, 2009-06-18 at 11:41 +0400, Igor S. wrote:

locaiton ~ ^/~([^/]+)(/?.)$) { (i changed to location ~ ^/~([^/]+)(/?.)$ {)
alias /home/$1/public_html/$2;
autoindex on;
}

this works well thanks. Are there any security risks with this? For
example could it be abused to gain access to another folder by using a
specific path ?

nginx normilizes “…” in URI, i.e., “/~user/…/dir/file” becomes
“/dir/file” and will not match this location.

“/~user/dir/…/file” becomes “/~user/file” and will be mapped by “alias”
to “/home/user/public_html/file”.

On Thu, Jun 18, 2009 at 12:17:31PM +0100, Jools W. wrote:

or you are saying this is a replacement for all the blocks of code I had
before ?

Yes, this is full replacememnt.