nginx 403禁止错误+ mac + laravel

时间:2016-10-21 07:26:32

标签: php laravel nginx

这是我的nginx的内容。

我当前的访问网址为http://localhost/lampi/,我收到了回复403 forbidden

我的服务器的文档是/ Library / WebServer / Documents /.

当我访问http://localhost/时,它显示正常。我还可以看到index.html页面的内容。

我不知道是怎么回事。我已经在stackoverflow中检查了前10页。

 server {

     server_name localhost;
     access_log  /var/log/nginx/nginx.host.access.log  main;

     root /Library/WebServer/Documents/;

     location / {
             #root html;
             index index.html index.htm index.php;
     }

     location /lampi {
             #autoindex on;
             if (!-e $request_filename){
                     rewrite  ^/lampi/(.*)$  /lampi/index.php?s=$1  last;
             }
     }

     location ~ \.php$ {
             include /usr/local/etc/nginx/fastcgi_params;
             fastcgi_pass 127.0.0.1:9000;
             fastcgi_index index.php;
             fastcgi_param   SCRIPT_FILENAME /Library/WebServer/Documents/lampi/$fastcgi_script_name;
     }

     location ~ [^/]\.php(/|$) {
             fastcgi_split_path_info ^(.+?\.php)(/.*)$;
             if (!-f $document_root$fastcgi_script_name) {
                     return 404;
             }

             fastcgi_param HTTP_PROXY "";
             fastcgi_pass 127.0.0.1:9000;

             fastcgi_index index.php;
             include fastcgi_params;
     }
     #location /images/ {
     #       root /usr/local/var/www;
     #}
 }

1 个答案:

答案 0 :(得分:0)

配置文件存在三个潜在问题。

使用if (!-e $request_filename)会导致问题,因为它会检查目录是否存在,并且您可能应该使用try_files(有关详细信息,请参阅this document):

location /lampi {
    try_files $uri $uri/ @lampi;
}
location @lampi {
    rewrite ^/lampi/(.*)$ /lampi/index.php?s=$1 last;
}

SCRIPT_FILENAME的值会在路径名中添加额外的/lampi。使用(在这种情况下评估为相同的值)中的任何一个:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $request_filename;

例如:

location ~ \.php$ {
    try_files $uri =404;

    include /usr/local/etc/nginx/fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $request_filename;
}

location ~ [^/]\.php(/|$)块令人困惑。通常,使用location ~ \.php$location ~ [^/]\.php(/|$)之类的内容就足够了,具体取决于您的应用程序是否使用PATH_INFO。删除您不使用的块。有关详细信息,请参阅this document

相关问题