【问题标题】:Access to the script '/path/to/script.php' has been denied (see security.limit_extensions)对脚本“/path/to/script.php”的访问已被拒绝(请参阅 security.limit_extensions)
【发布时间】:2016-12-30 10:59:33
【问题描述】:

在我列出我尝试过的之前:

  • This Answer on ServerFault
  • chmoded /Users/user/portal3 到 777 看是否执行
  • 创建了两个池,一个使用 root,另一个使用当前用户
  • 谷歌搜索
  • 在freenode中输入##php
  • 还有很多其他想法。

我在主目录中的子目录上执行 php 代码时遇到问题。 在 Nginx 上我得到了这个

2016/08/23 09:13:40 [error] 39170#0: *13 FastCGI sent in stderr: "Access to the script 
'/Users/user/portal3' has been denied (see security.limit_extensions)" while reading
response header from upstream, client: 127.0.0.1, server: localhost, request:
"GET /portal/v3/index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9001", host: "localhost"

在 php-fpm 上显示

[23-Aug-2016 09:13:40] WARNING: [pool dev] child 8305 said into stderr: "NOTICE: Access to the script '/Users/user/portal3' has been denied (see security.limit_extensions)"

我已经尝试了所有方法,但在 Mac 上使用 Nginx/PHP-FPM 运行 php 没有任何成功

Ngnix 和 PHP-FPM 以 root 身份运行

PHP-FPM 配置了两个池:

  • [www]: 以 root 身份运行并且工作正常,执行 php 代码,但它们的 www-root 子目录位于 /var/www
  • [dev] 池在 MacOS X 上以我当前用户身份运行,侦听端口 9001,并配置为在 /Users/user/portal3 中运行代码。

php-fpm.ini

[dev]
user=user
group=staff
listen=127.0.0.1:9001
listen.mode = 0666
pm = ondemand
pm.max_children = 10
pm.process_idle_timeout = 10s
pm.status_path = /status_user
catch_workers_output = yes
security.limit_extensions = .php

默认(在网站上可用)Nginx

server {
    listen       80;
    server_name  localhost;
    ###root /var/www/;
    access_log   /usr/local/etc/nginx/logs/default.access.log  main;
    access_log   /usr/local/etc/nginx/logs/default.scripts.log  scripts;

    location /portal/v3 {
        alias /Users/user/portal3;
        location ~  ^/portal/v3/(.+\.php)(/.*)$ {
            #alias /Users/user/portal3;
            index index.php;

            # Mitigate https://httpoxy.org/ vulnerabilities
            fastcgi_param HTTP_PROXY "";

            fastcgi_pass   127.0.0.1:9001;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$2;#$fastcgi_script_name;
            include fastcgi_params;
        }

    }

    location = /info {
        allow   127.0.0.1;
        deny    all;
        rewrite (.*) /.info.php;
    }

    location / {
        root /var/www/;
        index        index.php index.html index.htm;
        include   /usr/local/etc/nginx/conf.d/php-fpm;
    }

    error_page  404     /404.html;
    error_page  403     /403.html;
}

我已经使用自制软件安装了所有东西。现在我的想法不多了,我来这里寻求帮助。

【问题讨论】:

  • see security.limit_extensions了吗?
  • 是的...我有三张支票
  • 那之后,你做了什么改变来解决这个问题?
  • 你的配置中security.limit_extensions 的值是多少?
  • @Rafael ...因此只允许使用扩展名为.php 的文件,并且您正在尝试访问没有扩展名的文件。

标签: php macos nginx homebrew


【解决方案1】:

我今天早些时候也遇到了这个问题。我刚刚将文件扩展名从 .phtml 重命名为 .php 以立即修复它。

我后来在我的 php 配置文件(类似于 /etc/php/fpm/php-fpm.conf)中更改了我的 security.limit_extensions 设置以允许 .phtml(见下一行)

security.limit_extensions = .php .phtml

也可以用# 注释该行,如果是这种情况,只需通过删除# 来取消注释该行。

【讨论】:

    【解决方案2】:

    只需添加 FastCGI 参数 PATH_INFO 和 PATH_TRANSLATED。

    fastcgi_param    DOCUMENT_ROOT      /var/www/html;
    fastcgi_param    SCRIPT_FILENAME    /var/www/html$fastcgi_script_name;
    fastcgi_param    PATH_INFO          $fastcgi_path_info;
    fastcgi_param    PATH_TRANSLATED    $document_root$fastcgi_path_info;
    

    希望这对任何需要它的人也有帮助。

    【讨论】:

      【解决方案3】:

      在您的 PHP-FPM config 中,您有一个名为 security.limit_extensions 的指令

      限制 FPM 允许解析的主脚本的扩展。这可以防止 Web 服务器端的配置错误。您应该只将 FPM 限制为 .php 扩展名,以防止恶意用户使用其他扩展名执行 php 代码。默认值:.php。

      在您的情况下,因为您的 location 块不包含 index 指令,当路径指向 /Users/user/portal3 时,nginx 不知道使用 index.php 作为默认索引文件。相反,它尝试将其作为 PHP 脚本执行,并且 PHP-FPM 提出了 /Users/user/portal3 没有 .php 扩展名的安全限制。

      您的位置块应该看起来更像这样......

      location /portal/v3 {
          alias /Users/user/portal3;
          index index.php;
          location ~  ^/portal/v3/(.+\.php)(/.*)$ {
              fastcgi_param HTTP_PROXY "";
      
              fastcgi_pass   127.0.0.1:9001;
              fastcgi_index  index.php;
              fastcgi_param  SCRIPT_FILENAME $document_root$2;#$fastcgi_script_name;
              include fastcgi_params;
          }
      
      }
      

      【讨论】:

      • 或者,一个更好的主意,给文件一个允许的扩展名,这样你就不会随机地让每个文件都尝试被 PHP 解释:P
      • 好吧,确实没有名为 portal3 的脚本,它是一个子目录...所有站点都配置为创建一个对 url 友好的网站...实际上在 portal3 内部有一个 index.php 可以解析一切......所以也许这不是我想要的
      • 那将是一个 Web 服务器配置问题。因为根据这个,您的 Web 服务器不理解这是一个目录,因此没有尝试重写请求 URI 以指向 /Users/user/portal3/index.php。相反,它实际上尝试将/Users/user/portal3 作为PHP 脚本执行。所以更有可能是你的网络服务器的重写规则被破坏了。
      • $document_root$2;#$fastcgi_script_name;或 SCRIPT_FILENAME $document_root$fastcgi_script_name;
      猜你喜欢
      • 2015-10-04
      • 2014-04-15
      • 1970-01-01
      • 2011-01-01
      • 1970-01-01
      • 2021-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多