I don't use nginx, and I /know/ that many websites recommend the above
configuration change to enable "user" directories, but the "location" regexp
looks wrong to me.
Consider the part that reads:
^/~(.+?)(/.*)?$
This is meant to break the "path" part of the given URL into two components:
the users name, and the path component relative to the user's web directory.
Parsing starts at the first slash of the URL path component, ^/
requires a tilde ~
takes the characters up to the first slash as $1 (.+?)
takes any remaining characters as $2 (/.*)?
and plugs them into the alias
Now, to me, the problem is the regex component for the $1 assignment.
The brackets are regex metasymbols that group characters together; they are
there to indicate that the regex within the brackets will be taken as one,
and (in this case) substituted for $1. We can, for now, ignore the brackets,
leaving
.+?
The
.+
says that we require one or more (+) characters of any value (.), so
.+
matches a name.
But, what does the
?
signify.
It, too, is a metacharacter, and matches a count of zero or one of the
preceding character. But, there is no "preceding character" that it can
apply to. It looks /odd/ to me.
So, my suggestion is that the common instructions are incorrect, in that
the regex for $1 is malformed and won't work as expected.
You could try a slightly different regex:
^/~(.+)(/.*)?$
as in
location ~ ^/~(.+)(/.*)?$ {
alias /usr/home/$1/html/$2;
I don't guarantee this to work, but it makes more sense to me, and if it
fails then you are no further in trouble than you already are.
> location ~ .*~.*\.php$ {
> #root html;
> #try_files $uri =404;
> fastcgi_split_path_info ^(.+\.php)(/.+)$;
>
> # Mitigate
https://httpoxy.org/ vulnerabilities
> #fastcgi_param HTTP_PROXY "";
> fastcgi_pass unix:/var/run/php-fpm.sock;
> fastcgi_index index.php;
> fastcgi_param SCRIPT_FILENAME
> /usr/home/$1/html$fastcgi_script_name;
> include /usr/local/etc/nginx/fastcgi_params;
> }
>
> }
>
> Why am I not getting /usr/home/html/~doctor instead of
> /usr/home/doctor/html ?
HTH
--
Lew Pitcher
"In Skills, We Trust"