Post by J.O. AhoPost by The DoctorPost by Arno WelzelPost by The DoctorHow does one configure php, pl or cgi files is user subdirectories
on nginx ?
<https://www.google.com/search?q=nginx+php>
Tried that as well.
There is no different of configuring userdir from configuring a normal
location. You will need to configure for each file extension.
/usr/home//html/~doctor/blog/serendipity/comment.php (No +such file or
+46.229.168.152, server: www.nk.ca, request: "GET
+"fastcgi://unix:/var/run/php-fpm.sock:", host: "www.nk.ca" 2020/08/16
20:16:20 [error] 2707#100146: *1259 FastCGI sent in stderr: "Unable +to
open primary script: /usr/home//html/~doctor/blog/serendipity/index.php
(No +such file or directory)" while reading response header from upstream,
client: +116.202.106.130, server: www.nk.ca, request: "GET
+/~doctor/blog/serendipity/index.php?%2Ffeeds%2Findex_rss2= HTTP/1.1",
upstream: +"fastcgi://unix:/var/run/php-fpm.sock:", host: "www.nk.ca"
2020/08/16 20:22:22 [error] 2707#100146: *2014 open()
+"/usr/home/doctor/html/blog/serendipity/feeds/index.rss2" failed (2: No
such +file or directory), client: 51.254.168.38, server: www.nk.ca,
"www.nk.ca" 2020/08/16 20:22:23 [error] 2707#100146: *2028 open()
+"/usr/home/doctor/html/blog/serendipity/feeds/index.rss2" failed (2: No
such +file or directory), client: 51.254.168.38, server: www.nk.ca,
"http://www.nk.ca/~doctor/blog/serendipity/feeds/index.rss2"
And here is the configuration in question
location ~ ^/~(.+?)(/.*)?$ {
alias /usr/home/$1/html/$2;
index index.php index.phtml index.shtml index.html index.htm;
autoindex on;
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"