官方laravel nginx配置对我不起作用

时间:2018-05-19 14:08:06

标签: laravel nginx

在我的本地计算机上,official laravel documentation

的nginx配置不起作用
server {
    listen 80;
    server_name example.com;
    root /example.com/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

但它适用于几行的变化

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

更改为

location ~ \.php$ {
   include snippets/fastcgi-php.conf;
   fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}

一切正常。任何人都可以解释一下这段代码的不同之处并且它是不安全的吗?

1 个答案:

答案 0 :(得分:0)

只有合理的差异,我才会看到包含文件:snippets/fastcgi-php.conffastcgi_params

只需添加以下内容即可修复您的问题:

fastcgi_param  SCRIPT_FILENAME    $request_filename;

/etc/nginx/fastcgi_params档。

在旧版本的nginx中存在该行。 但是从1.10.x它被删除并成为空白屏幕的原因。