3

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

但是当我调整 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;
        }
    }

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

4

2 回答 2

14

替换这个

try_files $uri $uri/ =404;

try_files $uri $uri/ /index.php$is_args$args;

在那次跑步之后

sudo service nginx restart
于 2019-04-19T17:23:14.883 回答
0

尝试将 root 和 index 指令放在 server 块中(在 location 块之外),并将 try 文件修改为:try_files $uri $uri/ /index.php?$query_string;

此外,您在第 3 行有两次 server_name。

您可以在此处找到综合指南:https ://www.digitalocean.com/community/tutorials/how-to-deploy-a-laravel-application-with-nginx-on-ubuntu-16-04

于 2018-07-19T08:05:14.177 回答