설정되지 않은 헤더가 Apache 2.4.10 및 php-fpm에서 작동하지 않는 것 같습니다.

설정되지 않은 헤더가 Apache 2.4.10 및 php-fpm에서 작동하지 않는 것 같습니다.

다음과 같이 HTTP 헤더를 사용하여 PHP 코드의 헤더를 Apache 액세스 로그로 다시 전달하려고 합니다.

Header note X-Userid userid
Header unset X-Userid

LogFormat "%h %l %{userid}n %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined_with_php_userid
CustomLog /var/log/apache2/access_log combined_with_php_userid

를 사용하면 mod_php사용자 ID가 예상대로 로그에 삽입되고 헤더는 클라이언트로 전송되기 전에 설정 해제됩니다.

php-fpm을 통해 실행할 때 다음 줄을 사용하면 사용자 ID가 로그에 삽입되지 않으며 클라이언트 HTTP 헤더에서 설정이 해제되지 않습니다.

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9001/var/html/$1

원래는 사용하고 있었지만 apache_note이것은 mod_php. 위의 내용을 PHP에서 Apache/php-fpm 또는 nginx로 데이터를 전달하는 솔루션으로 찾았지만 php-fpm에서는 작동하지 않는 것 같습니다.

Header unsetphp-fpm에서 작업 하려면 활성화하거나 설정해야 할 것이 있습니까 ?

가상 호스트 구성:

<VirtualHost *:80>
    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9001/web/ee2/sites/site.com/$1
    ServerAdmin [email protected]
    DocumentRoot /web/ee2/sites/site.com
    ServerName site.dev

    Header note X-Userid userid
    Header unset X-Userid

    ErrorLog  /var/log/apache2/site.dev-error_log
    LogFormat "%h %l %{userid}n %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined_with_php_userid
    # also tried: # LogFormat "%h %l %{X-Userid}i %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined_with_php_userid
    CustomLog /var/log/apache2/searchenginenews.com-access_log combined_with_php_userid

    <Directory /web/ee2/sites/site.com>
        AllowOverride All
        Require all granted
    </Directory>

</VirtualHost>

답변1

mod_proxy_fcgi는 r->err_headers_out에 응답 헤더를 추가합니다. 이는 최소한 다음을 사용해야 함을 의미합니다.

Header unset X-Userid always

그러나 두 가지를 모두 사용하지 않을 이유가 없습니다.

Header always unset X-Userid
Header unset X-Userid

이는 mod_headers에 영향을 미치는 Apache API의 불행한 부분입니다. 헤더는 성공하지 못한 응답에 대해 지속되는지 여부에 따라 두 위치에 있을 수 있습니다.

답변2

댓글의 문제 해결에 따르면 이것이 버그라고 생각합니다. 에서 돌아오는 헤더는 어떤 식으로든 mod_proxy_fcgi사용할 수 없는 것 같고 처리 후 mod_headers데이터와 결합되고 있습니다 .mod_headers

현재로서는 이 동작이 올바르게 작동해야 한다면 nginx 또는 lighttpd를 보거나 Apache 앞에 HAProxy 또는 Varnish 인스턴스를 두어 올바른 방식으로 로깅 및 헤더 조작을 수행할 수 있습니까?

답변3

이 질문은 오래되었지만 최종 해결책을 찾는 사람에게 도움이 될 수 있습니다.

covener가 지적했듯이 Header unset메모를 설정할 때 '항상' 조건을 설정해야 합니다.

Header always note X-Userid userid
Header always unset X-Userid

변수에 대한 자리 표시자로 사용합니다 %{userid}n(mod_headers인 '내부 메모'의 n은 변수 값을 저장합니다.

로부터문서:

Header [condition] note header value

The optional condition argument determines which internal table 
of responses headers this directive will operate against. Despite the 
name, the default value of onsuccess does not limit an action to 
responses with a 2xx status code. Headers set under this condition are 
still used when, for example, a request is successfully proxied or 
generated by CGI, even when they have generated a failing status code.

관련 정보