Nginx 404 上的 Laravel

Nyi*_*cip 1 php nginx laravel lemp

我的 centos 7 VPS 中有两个站点。一个是 laravel 5.6(比如 def.com),另一个是静态 html 站点(比如 abc.com)。

使用此配置,html 站点运行顺利: sites-available/abc.com.conf

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

        # note that these lines are originally from the "location /" block
        #root   /var/www/abc.com/html;
        #index index.php index.html index.htm;

        location / {
            root   /var/www/abc.com/html;
            index index.php index.html index.htm;
            try_files $uri $uri/ =404;
        }
        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root /usr/share/nginx/html;
        }

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
Run Code Online (Sandbox Code Playgroud)

但是当我调整laravel项目的配置时,如下所示,它带有404

sites-available/def.com.conf

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

        # note that these lines are originally from the "location /" block
        #root   /var/www/def.com/public;
        #index index.php index.html index.htm;

        location / {
            root   /var/www/def.com/public;
            index index.php index.html index.htm;
            try_files $uri $uri/ =404;
        }
        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root /usr/share/nginx/html;
        }

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我正在使用本指南https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-on-centos-7

小智 8

替换这个

try_files $uri $uri/ =404;
Run Code Online (Sandbox Code Playgroud)

try_files $uri $uri/ /index.php$is_args$args;
Run Code Online (Sandbox Code Playgroud)

在那次跑步之后

sudo service nginx restart
Run Code Online (Sandbox Code Playgroud)