Apache不会为PHP脚本设置标头 [英] Apache won't set headers for PHP script

查看:88
本文介绍了Apache不会为PHP脚本设置标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.htaccess文件:

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 4 month"
</IfModule>
<IfModule mod_headers.c>
    Header merge X-ModHeaders "Yes, it is installed"
</IfModule>

...在我的开发箱(Windows箱,Apache/2.4.10,PHP作为Apache模块运行)中按预期工作,其中有效"表示它将为所有资源(静态或动态)生成适当的标头.

... works as expected in my development box (Windows box, Apache/2.4.10, PHP running as Apache module), where "works" means that it generates the appropriates headers for all resources (static or dynamic).

但是,在我的生产服务器(Linux机器,Apache/2.2.31,以FastCGI和mod_fcgid/2.3.9身份运行的PHP)中,它仅适用于静态资产,不适用于PHP脚本.

However, in my production server (Linux box, Apache/2.2.31, PHP running as FastCGI with mod_fcgid/2.3.9) it only works for static assets, not for PHP scripts.

我是否正确地怀疑差异来自PHP SAPI?有没有办法解决它,所以我不需要复制生成HTTP标头的代码?

Am I right suspecting that difference comes from the PHP SAPI? Is there a way to fix it so I don't need to duplicate the code that generates HTTP headers?

推荐答案

如果PHP通过mod_proxy_fcgi运行,则可能不涉及文件系统目录,因此不会发生htaccess查找.

If PHP is running via mod_proxy_fcgi there might be no filesystem directory involved, hence no htaccess lookup can occur.

使用SetHandler而不是ProxyPass的手册中现在记录了更新版本的php + mod_proxy_fcgi,它允许处理htaccess之类的内容,因为核心实际上是在文件系统中查找URL.

There is a more recent flavor of php+mod_proxy_fcgi now documented in the manual that uses SetHandler instead of ProxyPass -- that allows things like htaccess to be processed because the core actually looks up the URL in the filesystem as a first step.

这篇关于Apache不会为PHP脚本设置标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆