Score:0

Apache not sending headers to PHP over FCGI/PHP-FPM

cn flag

I have a virtual host configured to process PHP files over Proxy:FCGI, and it works fine, except that PHP is not receiving custom headers and others, like "Origin".

Here my Apache 2.4 virtual host:

<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>

and here, the PHP $_SERVER values returned:

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
)

I was expecting a header named "Example01" and others, but nothing. How can I make it work?

Score:0
cn flag

The instruction "CGIPassAuth On" solved my problem. My config changed from

    <Files ~ "\.php$">
        ProxyFCGIBackendType FPM
        SetHandler "proxy:fcgi://127.0.0.1:9002#"
    </Files>
</VirtualHost>

to

    <Files ~ "\.php$">
        CGIPassAuth On
        ProxyFCGIBackendType FPM
        SetHandler "proxy:fcgi://127.0.0.1:9002#"
    </Files>
</VirtualHost>
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.