【问题标题】:nginx 403 forbidden error + mac + laravelnginx 403 禁止错误 + mac + laravel
【发布时间】:2016-10-21 07:26:32
【问题描述】:

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

【问题讨论】:

    标签: php laravel nginx


    【解决方案1】:

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

    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

    【讨论】:

      猜你喜欢
      • 2015-02-02
      • 1970-01-01
      • 2019-01-23
      • 2017-08-18
      • 2013-07-19
      • 2016-03-26
      • 2017-07-15
      • 2017-12-20
      • 2011-05-31
      相关资源
      最近更新 更多