简体   繁体   中英

Php-fpm does not find the files from the chrooted nginx

I installed arch linux and nginx in a chroot ( archlinux wiki ). Thats working.

Now I want to get fastcgi running. I set the php-fpm socket to 127.0.0.1:9000 to reach it from the chroot (/srv/http).

While the html files are printed successfully the php-files are "not found". In the nginx-log I found this:

FastCGI sent in stderr: "primary script unknown" while reading response header from upstream, client: 10.211.55.2, server: localhost, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000:, host: "10.211.55.6".

So I think the php-fpm does not found the file, because the path is absolute in the nginx chroot and it searches in the real root. So I added, yes very ugly, the following to my settings, but there is no change of the result. How can I debug it, or better, find a clean solution?

location ~ \.php$ {
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    include       fastcgi_params;
    fastcgi_param SCRIPT_FILENAME  /srv/http$document_root$fastcgi_script_name
}

Tanks a lot.

FPM is looking in the wrong place.

Change your php-fpm configuration to add additional information on your access log file. My server is configured this way:

[www]
access.format = "%t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"

A sample line of the result of that configuration from my server:

07/Sep/2022:19:23:03 -0400 "GET index.php?q=/login&" 200 /nginx/ech11/public/index.php 23.787 2048 21.67%

In order, these options I use in my access logs:

  • %t is the current time (07/Sep/2022:19:23:03).
  • %m is the method (GET).
  • %r is the request URI (index.php?q=/login).
  • %Q is the glue between %q and %r (&).
  • %q is the query string. (empty in my example).
  • %s is the status (200).
  • %f is the script (/nginx/ech11/public/index.php)
  • %d is the duration µs (23.787).
  • %M is the memory (2048).
  • %C is the %CPU (21.67%).

That should inform you which settings to alter in the nginx.conf to enable fpm to find the index.php file.

Some other options you can use:

%e  fastcgi env
%l  content length
%n  pool name
%o  header output
%p  PID
%T  time

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM