我有一个虚拟主机配置为通过 Proxy:FCGI 处理 PHP 文件,并且它运行良好,只是 PHP 没有接收自定义标头和其他标头,例如“Origin”。
这是我的 Apache 2.4 虚拟主机:
<VirtualHost *:80>
ServerName domain.localhost
DocumentRoot "/my/host/directory/public"
DirectoryIndex index.html index.php
ErrorLog "/my/host/directory/logs/error.log"
CustomLog "my/host/directory/logs/access.log" common
SetEnv APPLICATION_ENV local
Header always set Example01 "*"
<Directory "my/host/directory/public">
AllowOverride All
Require all granted
</Directory>
<Files ~ "\.php$">
ProxyFCGIBackendType GENERIC
SetHandler "proxy:fcgi://127.0.0.1:9000#"
</Files>
</VirtualHost>
这里返回的是 PHP $_SERVER 值:
Array
(
[USER] => nobody
[HOME] => /var/empty
[SCRIPT_NAME] => /index.php
[REQUEST_URI] => /
[QUERY_STRING] =>
[REQUEST_METHOD] => GET
[SERVER_PROTOCOL] => HTTP/1.1
[GATEWAY_INTERFACE] => CGI/1.1
[REMOTE_PORT] => 55684
[SCRIPT_FILENAME] => /my/host/directory/public/index.php
[SERVER_ADMIN] => [email protected]
[CONTEXT_DOCUMENT_ROOT] => /my/host/directory/public
[CONTEXT_PREFIX] =>
[REQUEST_SCHEME] => http
[DOCUMENT_ROOT] => /my/host/directory/public
[REMOTE_ADDR] => 127.0.0.1
[SERVER_PORT] => 80
[SERVER_ADDR] => 127.0.0.1
[SERVER_NAME] => domain.localhost
[SERVER_SOFTWARE] => Apache/2.4.51 (Unix)
[SERVER_SIGNATURE] =>
[DYLD_LIBRARY_PATH] => /usr/local/apache-2.4.51/lib
[PATH] => /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
[HTTP_CONNECTION] => keep-alive
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_ACCEPT_LANGUAGE] => en-us
[HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[HTTP_HOST] => domain.localhost
[proxy-nokeepalive] => 1
[APPLICATION_ENV] => local
[FCGI_ROLE] => RESPONDER
[PHP_SELF] => /index.php
[REQUEST_TIME_FLOAT] => 1636663645.6605
[REQUEST_TIME] => 1636663645
)
我期望有一个名为“Example01”和其他名称的标头,但却没有。我该如何让它工作?
答案1
“CGIPassAuth On”指令解决了我的问题。我的配置从
<Files ~ "\.php$">
ProxyFCGIBackendType FPM
SetHandler "proxy:fcgi://127.0.0.1:9002#"
</Files>
</VirtualHost>
到
<Files ~ "\.php$">
CGIPassAuth On
ProxyFCGIBackendType FPM
SetHandler "proxy:fcgi://127.0.0.1:9002#"
</Files>
</VirtualHost>