【发布时间】:2021-06-23 17:03:22
【问题描述】:
我希望 Apache 默认将授权标头传递给 PHP。所以我将 Apache/2.4.29 (Ubuntu) 与 mod_php 一起使用,它允许“默认情况下通过 Apache 身份验证标头”。
这里是安装的 apache 模块。
核心mod_so mod_watchdog http_core mod_log_config mod_logio mod_version mod_unixd mod_access_compat mod_alias中mod_auth_basic mod_authn_core mod_authn_file模块mod_authz_core mod_authz_host mod_authz_user mod_autoindex mod_deflate模块mod_dir mod_env mod_filter mod_headers中mod_mime prefork的mod_negotiation模块mod_php7的mod_proxy的mod_proxy_ajp mod_proxy_balancer的mod_proxy_connect mod_proxy_html mod_proxy_http mod_proxy_wstunnel mod_reqtimeout mod_rewrite的mod_setenvif mod_slotmem_shm mod_socache_shmcb mod_ssl的mod_status的mod_xml2enc P>
这是我的虚拟主机配置。
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
ServerName piwal-elgg.com
DocumentRoot /xxxx/xxxx/xxxx/WEB/piwal
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /xxx/xxx/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /xxx/xxx/private/ssl-cert-snakeoil.key
<Directory /xxx/xxx/xxx/WEB/piwal>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
</IfModule>
我已经阅读了很多关于这个主题的文档,其中一些要求我在 .htaccess 文件中添加额外的规则。
其中一些角色如下。
1- .htaccess
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
2- .htaccess
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
3- .htaccess 或 apache 虚拟主机
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
4- .htaccess 或 apache 虚拟主机
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
5-.htaccess
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
以上设置均无效。 “默认情况下不传递 Apache 身份验证标头”。
但是当我将 RequestHeader set Authorization "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" 添加到我的 virtualHost 配置时。在这种情况下,标头已被服务器正确处理。
有人可以帮我解决这个问题吗?
这是我的 $_SERVER supergloble 数组的输出
Array
(
[REDIRECT_SCRIPT_URL] => /webdav/virtual/
[REDIRECT_SCRIPT_URI] => https://xxxx-xxxx.com/webdav/virtual/
[REDIRECT_HTTP_AUTHORIZATION] =>
[REDIRECT_HTTPS] => on
[REDIRECT_SSL_TLS_SNI] => xxxx-xxxx.com
[REDIRECT_STATUS] => 200
[SCRIPT_URL] => /webdav/virtual/
[SCRIPT_URI] => https://xxxx-xxxx.com/webdav/virtual/
[HTTP_AUTHORIZATION] =>
[HTTPS] => on
[SSL_TLS_SNI] => xxxx-xxxx.com
[HTTP_HOST] => xxxx-xxxx.com
[HTTP_USER_AGENT] => Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:86.0) Gecko/20100101 Firefox/86.0
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
[HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.5
[HTTP_ACCEPT_ENCODING] => gzip, deflate, br
[HTTP_CONNECTION] => keep-alive
[HTTP_COOKIE] => Elgg=or2a18jbqubrnkqk38mhhvguc5
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
[SERVER_SIGNATURE] => Apache/2.4.29 (Ubuntu) Server at xxxx-xxxx.com Port 443
[SERVER_SOFTWARE] => Apache/2.4.29 (Ubuntu)
[SERVER_NAME] => xxxx-xxxx.com
[SERVER_ADDR] => 127.0.1.1
[SERVER_PORT] => 443
[REMOTE_ADDR] => 127.0.0.1
[DOCUMENT_ROOT] => /xxxx/xxxx/xxxx/WEB/xxx-3-3-1
[REQUEST_SCHEME] => https
[CONTEXT_PREFIX] =>
[CONTEXT_DOCUMENT_ROOT] => /xxxx/xxxx/xxxx/WEB/xxx-3-3-1
[SERVER_ADMIN] => webmaster@localhost
[SCRIPT_FILENAME] => /xxxx/xxxx/xxxx/WEB/xxx-3-3-1/index.php
[REMOTE_PORT] => 41500
[REDIRECT_URL] => /webdav/virtual/
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[REQUEST_URI] => /webdav/virtual/
[SCRIPT_NAME] => /index.php
[PHP_SELF] => /index.php
[REQUEST_TIME_FLOAT] => 1616958400.0139
[REQUEST_TIME] => 1616958400
[PHP_AUTH_USER] =>
[PHP_AUTH_PW] =>
)
【问题讨论】:
标签: php apache .htaccess http-headers authorization