Apache“破坏”授权标头

Ale*_*lex 6 php apache .htaccess authorization

经过大量的研究和尝试和错误,我变得绝望了。

我正在使用 JwtAuthentication。我的客户正在发送标头授权就好了。几周前我没有遇到任何问题,但突然之间,我的 PHP 脚本(因此是 JwtAuthentication 中间件)无法“看到”授权标头,也无法“看到”我在 .htaccess 中声明的“SetEnv/SetEnvIf”变量文件。

我要求服务器中的活动模块(我为托管付费),看看是否启用了正确的模块,然后他们给我发送了这个:

  • core_module(静态)
  • so_module(静态)
  • http_module(静态)
  • mpm_worker_module(共享)
  • cgid_module(共享)
  • access_compat_module(共享)
  • actions_module(共享)
  • alias_module(共享)
  • auth_basic_module(共享)
  • authn_core_module(共享)
  • authn_file_module(共享)
  • authz_core_module(共享)
  • authz_groupfile_module(共享)
  • authz_host_module(共享)
  • authz_user_module(共享)
  • autoindex_module(共享)
  • deflate_module(共享)
  • dir_module(共享)
  • expires_module(共享)
  • filter_module(共享)
  • headers_module(共享)
  • include_module(共享)
  • log_config_module(共享)
  • logio_module(共享)
  • mime_module(共享)
  • 协商模块(共享)
  • proxy_module(共享)
  • proxy_fcgi_module(共享)
  • proxy_http_module(共享)
  • rewrite_module(共享)
  • setenvif_module(共享)
  • slotmem_shm_module(共享)
  • socache_dbm_module(共享)
  • socache_shmcb_module(共享)
  • status_module(共享)
  • suexec_module(共享)
  • unique_id_module(共享)
  • unixd_module(共享)
  • userdir_module(共享)
  • ssl_module(共享)
  • bwlimited_module(共享)
  • security2_module(共享)
  • suphp_module(共享)
  • 托管限制_模块(共享)

根据我一直在阅读的内容,重写 .htaccess 文件和使用 Authorization 标头的所有必要模块都处于活动状态,即使是那些能够使用 SetEnvIf 声明环境变量的模块(就像我说的,我不知道为什么我可以也不要使用它们)。

服务器配置如下: cPanel Version 58.0 (build 34) Apache Version 2.4.23 PHP Version 5.4.45 MySQL Version 5.6.33 Architecture x86_64 Operating System linux

我已经尝试过:

  • 添加CGIPassAuth on到 .htaccess
  • 像这样修改 RewriteCond:

    RewriteCond %{HTTP:Authorization} ^(.*) RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

  • SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

  • WSGIPAssAuthorization On .htaccess 文件导致 500 错误(我不知道为什么)
  • CGIPassAuth on 在 .htaccess 上没有任何改变。

而且……没有任何效果。我向托管人员询问有关 Apache 的变化,但他们告诉我没有任何变化。

和环境变量......为什么它们不起作用?

我知道还有其他问题,但不幸的是,他们提供的解决方案并没有解决我的问题。

是阿帕奇吗?是PHP吗?

在这里他们说这可能是防火墙问题,但如果是这样,环境应该可以工作,不是吗?而且不仅是我想将 Authorization 标头设置为变量;我设置的任何环境变量SetEnvSetEnvIf无法在我的 PHP 脚本中看到的任何环境变量。

可能是什么问题呢?

Ene*_*tlu 5

如果您使用 PHP-FPM 和 vhosts,您应该将其添加到您的 vhosts 文件中

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/local.mysite/htdocs/$1
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
SetEnvIf Content-Type "(.*)" HTTP_CONTENT_TYPE=$1
SetEnvIf Accept "(.*)" HTTP_ACCEPT=$1
Run Code Online (Sandbox Code Playgroud)

  • 由于**安全原因**,Apache 不会向脚本发送标头。PHP-FPM 无法发送任何标头,因此它没有。您将标头发送到 Apache 服务器 -> Apache 服务器使用标头对 PHP-FPM 进行代理 -> PHP-FPM 使用标头运行您的 php 脚本。清楚吗? (2认同)

aed*_*ols 4

在不小心将 MAMP PHP 设置从模块切换到 CGI 后,我开始遇到相同的症状。

据我所知出于多种原因,模块更可取。

检查服务器上的等效设置并根据需要进行更改。