Apache“销毁”授权标题

时间:2016-11-08 18:41:56

标签: php apache .htaccess authorization

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

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

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

  • core_module(静态)
  • so_module(静态)
  • http_module(静态)
  • mpm_worker_module(共享)
  • cgid_module(共享)
  • access_compat_module(shared)
  • 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(shared)
  • log_config_module(共享)
  • logio_module(共享)
  • mime_module(共享)
  • negotiation_module(shared)
  • proxy_module(共享)
  • proxy_fcgi_module(共享)
  • proxy_http_module(共享)
  • rewrite_module(共享)
  • setenvif_module(共享)
  • slotmem_shm_module(共享)
  • socache_dbm_module(共享)
  • socache_shmcb_module(共享)
  • status_module(shared)
  • suexec_module(共享)
  • unique_id_module(共享)
  • unixd_module(共享)
  • userdir_module(共享)
  • ssl_module(共享)
  • bwlimited_module(共享)
  • security2_module(共享)
  • suphp_module(共享)
  • hostinglimits_module(共享)

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

服务器配置如下: cPanel版本58.0(build 34) Apache版本2.4.23 PHP版本5.4.45 MySQL版本5.6.33 架构x86_64 操作系统linux

我已经尝试过了:

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

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

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

  • .htaccess文件中的
  • WSGIPAssAuthorization On导致500错误(我不知道为什么)
  • .htaccess上的
  • CGIPassAuth on不做任何更改。

而且......没有任何效果。我问主持人有关Apache的变化,但他们告诉我没有任何改变。

环境变量......他们为什么不工作?

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

是Apache吗? 是PHP吗?

Here他们说这可能是防火墙问题,但如果是这样,环境应该有效,不是吗?并且不仅仅是我想将Authorization标头设置为变量;我在PHP脚本中看不到通过SetEnvSetEnvIf设置的任何环境变量。

可能是什么问题?

2 个答案:

答案 0 :(得分:4)

我意外地将MAMP PHP设置从Module切换到CGI后,我开始遇到相同的症状。

从我read开始,出于多种原因,模块更受欢迎。

Check the equivalent setting在您的服务器上并在必要时进行更改。

答案 1 :(得分:1)

如果您使用PHP-FPM和vhost,则应将其添加到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