php not working from aliased subdir

Francis Daly francis at daoine.org
Tue Jan 31 20:13:35 UTC 2017


On Tue, Jan 31, 2017 at 08:43:23AM +0200, Nikolaos Milas wrote:
> On 19/1/2016 10:58 μμ, Francis Daly wrote:

Hi there,

> I have tried various things with the aliased directories, but I am
> still having the problem.

> My logic is to use a scheme like (see full details in the attached config):

The logic skeleton looks right to me, for what that's worth.

> But it doesn't work for the aliased dirs.
> 
> The request in question (http://www-xxx.noa.gr/museum/library/)
> should access the file:
> 
>    http://www-xxx.noa.gr/museum/library/index.php
> 
> (i.e. file: /var/webs/wwwopenbib/index.php) whose content is:

>     location ^~ /museum/library/ {
>         alias /var/webs/wwwopenbib/;
>         allow 10.201.0.0/16;
>         deny all;
> 
>         location ~ \.php$ {
> 
>         fastcgi_param SCRIPT_FILENAME /var/webs/wwwopenbib$fastcgi_script_name;

I suspect that changing that line will make everything work.

$fastcgi_script_name is something like /museum/library/index.php, so
SCRIPT_FILENAME ends up with a value that is not exactly the name of
the file that you want.

Replace the line with

    fastcgi_param SCRIPT_FILENAME $request_filename;

and reload.

The debug log does show what is going on, if you are able to ignore the extra lines.

First, for the request /museum/library/ :

> 2017/01/31 08:17:24 [debug] 15750#15750: *149615 using configuration "/museum/library/"

it chooses the location you want...

> 2017/01/31 08:17:24 [debug] 15750#15750: *149615 internal redirect: "/museum/library/index.php?"

and issues the (internal) subrequest. This request also chooses the
location you want:

> 2017/01/31 08:17:24 [debug] 15750#15750: *149615 using configuration "\.php$"

(although that is not immediately obvious, unless you know what to
expect). And then it prepares the parameters to send to the fastcgi
server:

> 2017/01/31 08:17:24 [debug] 15750#15750: *149615 http script copy: "SCRIPT_FILENAME"
> 2017/01/31 08:17:24 [debug] 15750#15750: *149615 http script copy: "/var/webs/wwwopenbib"
> 2017/01/31 08:17:24 [debug] 15750#15750: *149615 http script var: "/museum/library/index.php"
> 2017/01/31 08:17:24 [debug] 15750#15750: *149615 fastcgi param: "SCRIPT_FILENAME: /var/webs/wwwopenbib/museum/library/index.php"

That is the filename that your fastcgi server is going to try (and fail)
to open.

> 2017/01/31 08:17:24 [error] 15750#15750: *149615 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: ::ffff:195.251.202.164, server: www-xxx.noa.gr, request: "GET /museum/library/ HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-fpm.sock:", host: "www-xxx.noa.gr"

And there it is reporting failure.

> 2017/01/31 08:17:24 [debug] 15750#15750: *149615 http fastcgi header: "Status: 404 Not Found"
> 2017/01/31 08:17:24 [debug] 15750#15750: *149615 http fastcgi header: "X-Powered-By: PHP/5.6.22"
> 2017/01/31 08:17:24 [debug] 15750#15750: *149615 http fastcgi header: "Content-type: text/html; charset=UTF-8"

And that is what it sent back to nginx as the response.


Compare http://nginx.org/r/$fastcgi_script_name with
http://nginx.org/r/$request_filename to see why you probably want the
latter in each case you use "alias".

Cheers,

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list