Nginx如何解决File not found 404 Not Found配置

第一种情况

location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;这里改为 $document_root

第二种情况

server {
listen 80;
server_name v1.ywwfx.com;
root /home/www/www.96net.com.cn;

}

root /home/www/www.96net.com.cn;目录权限不够导致的

jnzzyl.com 是文件名称
linux更改权限命令
chown -R 777 jnzzyl.com
更改权限www拥有者命令
chown -R www:www jnzzyl.com

第三种情况

vim /etc/php-fpm.d/www.conf

user=nginx

group=nginx

这些都设置后  重启nginx  php-fpm 就可以运行了

如果依然不想,附上一下代码

server {
    listen       80;
    server_name  www.jnzzyl.com;

    if ($host ~ "\d+\.\d+\.\d+\.\d") {
        return 404;#禁IP访问
    }
    root /data/www/jnzzyl.com;
    index  index.html index.htm index.php;

    error_page  404              /404.html;
    location = /404.html {
        return 404 'Sorry, File not Found!';
    }
    error_page  500 502 503 504  /50x.html;
    location = /50x.html {
        root   /data/www/jnzzyl.com; # windows用户替换这个目录
    }

    location / {
        try_files $uri @rewrite;
    }

    location @rewrite {
        set $static 0;
        if  ($uri ~ \.(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css\.map|min\.map)$) {
            set $static 1;
        }

        if ($static = 0) {
            rewrite ^/(.*)$ /index.php?s=/$1;
        }

    }

    location ~ /Uploads/.*\.php$ {
        deny all;
    }

    location ~ \.php/ {
       if ($request_uri ~ ^(.+\.php)(/.+?)($|\?)) { }
       fastcgi_pass 127.0.0.1:9000;
       include fastcgi_params;
       fastcgi_param SCRIPT_NAME     $1;
       fastcgi_param PATH_INFO       $2;
       fastcgi_param SCRIPT_FILENAME $document_root$1;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny  all;
    }
}

你可能感兴趣的:(PHP)