nginx + php-fpm = File not found

前端 未结 8 1686
孤街浪徒
孤街浪徒 2021-02-07 01:25

When i try accessing info.php I get a File not found. error.

I tried some Tutorials to no avail.

Configs: default:

ser         


        
相关标签:
8条回答
  • 2021-02-07 01:59
    server {
    listen         80;
    listen   [::]:80 default ipv6only=on; 
    server_name  localhost;
    root   /var/www;
    location / {
        index index.php;
    }
    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;
    }
    

    }

    0 讨论(0)
  • 2021-02-07 02:03

    I came across this whilst trying to solve a similar problem. So I'll add the solution I found when I got to it. This was on Arch, but it is systemd related.

    This solution is for my development machine, and for good reasons, you shouldn't run a public site from your /home folder.

    I configured php-fpm and nginx to run as my user. Edit the following file, and remove the ProtectHome=true line

    sudo vi /etc/systemd/system/multi-user.target.wants/php-fpm.service
    

    Reload, and restart everything;

    systemctl daemon-reload
    systemctl restart nginx.service
    systemctl restart php-fpm.service
    
    0 讨论(0)
  • 2021-02-07 02:05

    If that info.php is in /var/www, then it's wrong to instruct fast_cgi to look for

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

    Use the same root for html and php. Also, root and index parameters should be outside a particular location except for very specific uses.

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

    needless to say, you still need to make sure your php-fpm service is listening at port 7777. Common case is to have it listening at port 9000.

    0 讨论(0)
  • 2021-02-07 02:06

    I had this issue and none of the answers here worked. The issue for me ended up being caused by SELinux. I disabled SELinux and it fixed the issue.

    Be aware that disabling SELinux does have an impact on security. There's almost certainly a better way to fix this, but disabling SELinux works for my purposes.

    0 讨论(0)
  • 2021-02-07 02:08

    If you checked every thing and it's correct configured, then there is last point i got:

    • check that correct username if mentioned in file /etc/php-fpm.d/www.conf
    0 讨论(0)
  • 2021-02-07 02:10

    I took a long look at this, in the end turned out that FPM wasn't running :-s in my case a simple service php7.2-fpm restart did the trick!

    0 讨论(0)
提交回复
热议问题