Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Nginx and php,pl,cgi in users subdirectory

43 views
Skip to first unread message

The Doctor

unread,
Aug 19, 2020, 5:52:51 PM8/19/20
to
How does one configure php, pl or cgi files is user subdirectories
on nginx ?
--
Member - Liberal International This is doctor@@nl2k.ab.ca Ici doctor@@nl2k.ab.ca
Yahweh, Queen & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b
New Brunswick Save The PRovince Vote Liberal 14 Sept!!

Jerry Stuckle

unread,
Aug 19, 2020, 9:16:11 PM8/19/20
to
On 8/19/2020 5:52 PM, The Doctor wrote:
> How does one configure php, pl or cgi files is user subdirectories
> on nginx ?
>

Configuring PHP for a particular web server or OS is part of that
installation's configuration, not PHP itself. I suggest you look at
nginx documentation and/or for a group of forum related to nginx (or, in
the case of Linux, your distro may have information. You'll get much
better answers.,

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstu...@attglobal.net
==================

The Doctor

unread,
Aug 19, 2020, 10:22:11 PM8/19/20
to
In article <rhkisp$p6s$1...@jstuckle.eternal-september.org>,
Jerry Stuckle <jstu...@attglobal.net> wrote:
>On 8/19/2020 5:52 PM, The Doctor wrote:
>> How does one configure php, pl or cgi files is user subdirectories
>> on nginx ?
>>
>
>Configuring PHP for a particular web server or OS is part of that
>installation's configuration, not PHP itself. I suggest you look at
>nginx documentation and/or for a group of forum related to nginx (or, in
>the case of Linux, your distro may have information. You'll get much
>better answers.,
>

Tried sending an e-mail to the nginx list only that a bnch on
SPF et al
has screwed things up.

>--
>==================
>Remove the "x" from my email address
>Jerry Stuckle
>jstu...@attglobal.net
>==================


Arno Welzel

unread,
Aug 20, 2020, 3:46:39 AM8/20/20
to
The Doctor:

> How does one configure php, pl or cgi files is user subdirectories
> on nginx ?

<https://www.google.com/search?q=nginx+php>


--
Arno Welzel
https://arnowelzel.de

The Doctor

unread,
Aug 20, 2020, 8:57:17 AM8/20/20
to
In article <hq6o2t...@mid.individual.net>,
Arno Welzel <use...@arnowelzel.de> wrote:
>The Doctor:
>
>> How 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.

>
>--
>Arno Welzel
>https://arnowelzel.de


J.O. Aho

unread,
Aug 20, 2020, 11:16:33 AM8/20/20
to
On 20/08/2020 14.57, The Doctor wrote:
> In article <hq6o2t...@mid.individual.net>,
> Arno Welzel <use...@arnowelzel.de> wrote:
>> The Doctor:
>>
>>> How 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.

--

//Aho

The Doctor

unread,
Aug 20, 2020, 6:16:36 PM8/20/20
to
In article <hq7ief...@mid.individual.net>,
did that. here is the error I am getting:

Logs:

2020/08/16 20:05:09 [error] 1971#100506: *623 FastCGI sent in stderr: "Unable to
+open primary script: /usr/home//html/~doctor/blog/serendipity/comment.php (No
+such file or directory)" while reading response header from upstream, client:
+46.229.168.152, server: www.nk.ca, request: "GET
+/~doctor/blog/serendipity/comment.php HTTP/1.1", upstream:
+"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, request: "GET
+/~doctor/blog/serendipity/feeds/index.rss2 HTTP/1.0", host: "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, request: "GET
+/~doctor/blog/serendipity/feeds/index.rss2 HTTP/1.1", host: "www.nk.ca",
+referrer: "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;


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 ?

>--
>
> //Aho

Lew Pitcher

unread,
Aug 20, 2020, 7:24:53 PM8/20/20
to
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"

Eli the Bearded

unread,
Aug 20, 2020, 8:14:37 PM8/20/20
to
In comp.infosystems.www.servers.unix,
Lew Pitcher <lew.p...@digitalfreehold.ca> wrote:
> Consider the part that reads:
> ^/~(.+?)(/.*)?$
> This is meant to break the "path" part of the given URL into two components:
...
> The
> .+
> says that we require one or more (+) characters of any value (.), so
> .+
> matches a name.
> But, what does the
> ?
> signify.

In PCRE the syntax "+?" indicates the MINIMAL (non-greedy) number of the
proceeding item to satisfy context, as opposed to plain "+" being the
MAXIMAL (greedy) match. In the case of

^/~(.+?)(/.*)?$

It effectively means the first period will never match "/". In some
contexts, using non-greedy matches can have surprising results. In
particular if any of the context is multiple literal characters, when
an exact literal might not be true.[*] I try to avoid non-greedy when
possible, eg:

^/~([^/]+)(/.*)?$

But non-greedy is safe and not wrong (here), so it can be used.

> 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:
> ^/~(.+)(/.*)?$

That will break when there are subdirectories, becuase the first + is
greedy.
Input: /~lew/have/I/got/an/example/for/you
Output: $1 = /~lew/have/I/got/an/example/for
$2 = /you


[*] One of the classic examples comes from naive parsing of HTML.
<a.*?href="(.*?)">

Works fine on input <a href="https://qaz.wtf/">
-> $1 = https://qaz.wtf/

Works fine on input <a class="link" href="https://qaz.wtf/">
-> $1 = https://qaz.wtf/

Works poorly on input <a href="https://qaz.wtf/" class="link">
-> $1 = https://qaz.wtf/" class="link

Works TERRIBLY on input
<a href="foob.html" class='link'>Ten paragraphs</a> of html
follow all without any <A> tags. And then
<a href="https://qaz.wtf/" class="link">
-> $1 = foob.html" class='link'>Ten paragraphs</a> of html
follow all without any <A> tags. And then
<a href="https://qaz.wtf/" class="link

Elijah
------
never uses user directories any more and hasn't looked at the problem here

The Doctor

unread,
Aug 20, 2020, 10:59:40 PM8/20/20
to
In article <eli$20082...@qaz.wtf>,
Just because you find this in a search engine does not make it correct.

Same result/ https://domain.name/~user/ works

but not the subdirectories.

J.O. Aho

unread,
Aug 21, 2020, 4:47:57 AM8/21/20
to
On 21/08/2020 00.16, The Doctor wrote:
> In article <hq7ief...@mid.individual.net>,
> J.O. Aho <us...@example.net> wrote:
>> On 20/08/2020 14.57, The Doctor wrote:
>>> In article <hq6o2t...@mid.individual.net>,
>>> Arno Welzel <use...@arnowelzel.de> wrote:
>>>> The Doctor:

We are quite off topic for c.l.p, so that why an OT in the subject.


>>>>> How 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.
>>
>
> did that. here is the error I am getting:
> location ~ ^/~(.+?)(/.*)?$
> Logs:
>
> 2020/08/16 20:05:09 [error] 1971#100506: *623 FastCGI sent in stderr: "Unable to
> +open primary script: /usr/home//html/~doctor/blog/serendipity/comment.php (No
> +such file or directory)" while reading response header from upstream, client:
> +46.229.168.152, server: www.nk.ca, request: "GET

Your regexp is incorrect, as Lew pointed out, but sadly his regexp will
have same kind of issue and even if it had been working, there had been
problem with potentially access directories that are not to ment to be
served.

The regexp you are looking for is: ^/~([\w-]*)(/.*)?$

Next time you have issues with regexp in nginx, take a look at
https://www.regextester.com/94055 and use the substitution section to
see what values you really get.


> alias /usr/home/$1/html/$2;
> Why am I not getting /usr/home/html/~doctor instead of /usr/home/doctor/html ?

I don't think you should have the tilde in the directory name, if you
want to change the order, then you have to change the order in your
alias, $1 is the username, the $2 is the path, so if you have
/user/home/html directory filled with users web directories, tne you
should have /usr/home/html/$1/$2. If you need to keep the tilde in the
username, then you have to move the tilde in the regexp so it's inside
the parentheses, but I recommend against that.


> 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;
> }

This looks really messy and another potential error source.

location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
}

that should be neater and less prone to fail.


PS. When you reply, remove the footer(s) if your news client don't
manage to remove footers by itself.

--

//Aho

The Doctor

unread,
Aug 21, 2020, 9:22:44 AM8/21/20
to
In article <hq9g1s...@mid.individual.net>,
You have to wonder why apache is viewed as bloatware
yet converting to nginx is not that straight forword

esp when subdirectories and php gets involed.

J.O. Aho

unread,
Aug 21, 2020, 2:16:20 PM8/21/20
to
On 21/08/2020 15.21, The Doctor wrote:

> You have to wonder why apache is viewed as bloatware
> yet converting to nginx is not that straight forword
>
> esp when subdirectories and php gets involed.

I would say they are quite different products and the aim has been
different. Apache is simple to configure the defaults while nginx gives
you a lot more freedom at the cost of more difficult configurations.

--

//Aho

The Doctor

unread,
Aug 21, 2020, 6:57:46 PM8/21/20
to
In article <hqahbi...@mid.individual.net>,
Well have you looks at Netcraft's Web Survey lately?

The Doctor

unread,
Aug 21, 2020, 10:24:20 PM8/21/20
to
In article <rhpjh9$2go0$5...@gallifrey.nk.ca>,
The Doctor <doc...@doctor.nl2k.ab.ca> wrote:
>In article <hqahbi...@mid.individual.net>,
>J.O. Aho <us...@example.net> wrote:
>>On 21/08/2020 15.21, The Doctor wrote:
>>
>>> You have to wonder why apache is viewed as bloatware
>>> yet converting to nginx is not that straight forword
>>>
>>> esp when subdirectories and php gets involed.
>>
>>I would say they are quite different products and the aim has been
>>different. Apache is simple to configure the defaults while nginx gives
>>you a lot more freedom at the cost of more difficult configurations.
>>
>>--
>>
>> //Aho
>
>Well have you looks at Netcraft's Web Survey lately?


Got it to work.

best answer:

https://www.linode.com/community/questions/6502/nginx-php-in-a-users-public_html

Arno Welzel

unread,
Aug 23, 2020, 7:50:26 AM8/23/20
to
The Doctor:

> In article <hqahbi...@mid.individual.net>,
> J.O. Aho <us...@example.net> wrote:
>> On 21/08/2020 15.21, The Doctor wrote:
>>
>>> You have to wonder why apache is viewed as bloatware
>>> yet converting to nginx is not that straight forword
>>>
>>> esp when subdirectories and php gets involed.
>>
>> I would say they are quite different products and the aim has been
>> different. Apache is simple to configure the defaults while nginx gives
>> you a lot more freedom at the cost of more difficult configurations.
>>
>> --
>>
>> //Aho
>
> Well have you looks at Netcraft's Web Survey lately?

What does this have to do with the question of how difficould or easy it
is to configure? nginx is not used because it is so simple to set up but
because of its performance.

The Doctor

unread,
Aug 23, 2020, 8:38:09 AM8/23/20
to
In article <hqf3g0...@mid.individual.net>,
And that is why the competition is on.

Anyways I answers earlier with a link.
>
>--
>Arno Welzel
>https://arnowelzel.de


Arno Welzel

unread,
Aug 23, 2020, 8:01:42 PM8/23/20
to
The Doctor:

> In article <hqf3g0...@mid.individual.net>,
> Arno Welzel <use...@arnowelzel.de> wrote:
>> The Doctor:
>>
>>> In article <hqahbi...@mid.individual.net>,
>>> J.O. Aho <us...@example.net> wrote:
>>>> On 21/08/2020 15.21, The Doctor wrote:
>>>>
>>>>> You have to wonder why apache is viewed as bloatware
>>>>> yet converting to nginx is not that straight forword
>>>>>
>>>>> esp when subdirectories and php gets involed.
>>>>
>>>> I would say they are quite different products and the aim has been
>>>> different. Apache is simple to configure the defaults while nginx gives
>>>> you a lot more freedom at the cost of more difficult configurations.
>>>>
>>>> --
>>>>
>>>> //Aho
>>>
>>> Well have you looks at Netcraft's Web Survey lately?
>>
>> What does this have to do with the question of how difficould or easy it
>> is to configure? nginx is not used because it is so simple to set up but
>> because of its performance.
>>
>
> And that is why the competition is on.

Did I doubt this anywhere?
0 new messages