nginx + php-fpm = 找不到文件

2022-08-30 17:46:09

当我尝试访问时,我收到一个错误。info.phpFile not found.

我尝试了一些教程,但无济于事。

配置:默认:

server {
    listen         80;
    listen   [::]:80 default ipv6only=on; 
    server_name  localhost;

    location / {
        root   /var/www;
        index  index.html index.htm index.php;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:7777;
        fastcgi_index  index.php;
        fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
        fastcgi_buffers 256 128k;
        #fastcgi_buffer_size 16k;
        #fastcgi_busy_buffers_size 256k;
        fastcgi_connect_timeout 300s;
        fastcgi_send_timeout 300s;
        fastcgi_read_timeout 300s;
        include fastcgi_params;
    }
}

怎么了?


答案 1

如果该信息.php位于 /var/www 中,则指示fast_cgi查找是错误的

/usr/share/nginx/html/info.php;

对 html 和 php 使用相同的根。此外,参数应该在特定位置之外,但非常具体的用途除外。rootindex

server {
   listen         80;
   listen   [::]:80 default ipv6only=on; 
   server_name  localhost;
   root   /var/www;
   index  index.html index.htm index.php;


   #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

   location ~ \.php$ {
       fastcgi_pass 127.0.0.1:7777;
       fastcgi_index  index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       fastcgi_buffers 256 128k;
       fastcgi_connect_timeout 300s;
       fastcgi_send_timeout 300s;
       fastcgi_read_timeout 300s;
       include fastcgi_params;
    }
}

毋庸置疑,您仍然需要确保您的php-fpm服务在端口7777上侦听。常见的情况是让它在端口 9000 处侦听。


答案 2

如果你检查了每一件事,并且它配置正确,那么我得到了最后一点:

  • 检查正确的用户名(如果在文件中提到)/etc/php-fpm.d/www.conf

推荐