404 error with any php file, using nginx

2019-07-25 10:55发布

I realize this question has been asked numerous times, yet despite all my attempts to put in place the various solutions many have suggested I have yet to solve my problem:

no matter what I do, any php file on my website gives me a 404 error. html files work perfectly, however.

my nginx.conf:

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POOD$
        ssl_prefer_server_ciphers on;

        access_log /home/****/websites/logs/access.log;
        error_log /home/****/websites/logs/error.log;

        include v-hosts/*.conf;
        #### prevent processing requests with undefined server names
        server  {
                listen 80;
                server_name '';
                return 444;
        }


}

my /etc/nginx/v-hosts/website.com.conf

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /home/*****/websites/website.com/root;
    index index.php index.html index.htm;

    server_name website.com www.website.com;

    location / {
        try_files $uri $uri/ =404;
        root /home/****/websites/website.com/root;
        index index.php index.html index.html;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root /home/****/websites/website.com/root;
    }

    location ~ \.php$ {
        root /home/****/websites/website.com/root;
        try_files $uri =404;

        fastcgi_pass unix:/run/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        }
}
  • I have set cgi.fix_pathinfo=0 in php.ini
  • I have an index.php as well as an info.php in /home/****/websites/website.com/root

thank you

标签: php nginx
1条回答
老娘就宠你
2楼-- · 2019-07-25 11:16

I have successfully fixed my issue! after accessing the error log in /home/****/websites/logs/error.log , I realized my path fastcgi_pass unix:/run/php7.0-fpm.sock; was wrong. I have changed it to fastcgi_pass unix:/run/php/php7.0-fpm.sock; and the page now displays correctly!

`

查看更多
登录 后发表回答