AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 646773
Accepted
Ian
Ian
Asked: 2014-11-25 13:04:12 +0800 CST2014-11-25 13:04:12 +0800 CST 2014-11-25 13:04:12 +0800 CST

未设置的标头似乎不适用于 apache 2.4.10 和 php-fpm

  • 772

我正在尝试使用 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,用户标识按预期插入到日志中,并且在发送到客户端之前未设置标头。

通过 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 unset在 php-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>
php-fpm
  • 3 3 个回答
  • 3349 Views

3 个回答

  • Voted
  1. Best Answer
    covener
    2014-12-03T19:22:05+08:002014-12-03T19:22:05+08:00

    mod_proxy_fcgi 将响应头添加到 r->err_headers_out 这意味着您至少应该使用:

    Header unset X-Userid always
    

    但是没有理由不同时使用两者:

    Header always unset X-Userid
    Header unset X-Userid
    

    这是 Apache API 中一个不幸的部分,它渗入 mod_headers —— 标头可以存在于两个地方,这取决于它们是否要为不成功的响应而持续存在。

    • 4
  2. Shane Madden
    2014-11-25T14:53:55+08:002014-11-25T14:53:55+08:00

    从评论中的故障排除来看,我认为这是一个错误——返回的标头mod_proxy_fcgi似乎无法以mod_headers任何方式使用,并且正在与mod_headers处理后的数据相结合。

    现在,如果您需要这种行为正常工作,也许看看 nginx 或 lighttpd,或者在 Apache 前面拍一个 HAProxy 或 Varnish 实例,以正确的方式进行日志记录和标头操作?

    • 2
  3. Diego
    2017-09-01T13:29:54+08:002017-09-01T13:29:54+08:00

    这个问题很老,但可能有助于寻找最终解决方案的人:

    正如 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.
    
    • 1

相关问题

  • 不小心将 chown “root” 设置为我所有的服务器

  • Nginx + PHP-FPM = "随机" 502 错误网关

  • PHP-FPM + NGINX:PHP-CGI 进程在空闲一段时间后死亡,然后 502 bad gateway 和需要手动重启

  • 如何使程序从源代码保持最新?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve