在httpd.conf中设置标题不会在.htaccess中设置标题 [英] Setting headers in httpd.conf not setting headers in .htaccess

查看:131
本文介绍了在httpd.conf中设置标题不会在.htaccess中设置标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题:

我有一堆标题,对于服务器上的每个网站都是相同的。我认为 只能在 httpd.conf 中设置一次,这样可以避免每次有新的添加时将写入.htaccess的内容写成一堆。

I have a bunch of headers that are the same for every website on a server. I think " this can be set just once in httpd.conf so as to save writing out into a pile of .htaccess every time there's a new one to add / change. "

这就是我要做的;

httpd.conf 文件中虚拟主机之前,我设置了:

<IfModule mod_headers.c>
  <Directory '/'>
Header always set Feature-Policy "accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'"
Header always set Cache-Control no-cache,must-revalidate
Header always set X-Clacks-Overhead "GNU Terry Pratchett"
Header always set X-XSS-Protection 1;mode=block
Header always set X-Content-Type-Options nosniff
Header always set X-Frame-Options SAMEORIGIN
Header always set Content-Language en
Header always set Referrer-Policy origin-when-cross-origin
Header unset Last-Modified
Header unset X-Powered-By
Header always set Strict-Transport-Security "max-age=31536000;" "expr=%{HTTPS} == 'on'"
Header always set Expect-CT enforce,max-age=2592000
  </Directory>
</IfModule>

但是,这样做并重新启动Apache(版本2.4.37)后,我发现或 .htaccess 中编辑的 Header 指令未发送。

However, after doing this and hard restarting the Apache (version 2.4.37), I find that additional or edited Header instructions in the .htaccess are not being sent.

例如;每个帐户都有自己的CSP策略,这反映在帐户 public_html / .htaccess 文件中:

For example; each account has its own CSP policy and this is reflected in the account public_html/.htaccess file:

示例:

Header set Content-Security-Policy "upgrade-insecure-requests; default-src 'self' https:;"

但是任何浏览器读取标头时,接收到的标头只是来自httpd.conf的标头并且 .htaccess 中没有显示其他标题或更改过的标题。

But when the headers are read by any browser the headers recieved are only the ones from the httpd.conf and no addditional or changed headers are showing from the .htaccess.

我不知道为什么?


  • 我将标头包裹在<$限定符< IfModule ...> 语句中的c $ c> .htaccess 。

  • I已经使用了不同的浏览器来迫使apache重新读取
    .htaccess文件。

  • 我已经阅读过google,找不到与htaccess读取标题混淆的httpd.conf引用。

  • .htaccess 文件的其他部分都可以正常读取。

  • I have wrapped the headers in the .htaccess in qualifier <IfModule ...> statements.
  • I have used different browsers to force apache to reread the .htaccess files.
  • I have read google and can find no reference of httpd.conf messing with htaccess reading of headers.
  • Other parts to the .Htaccess files are being read ok.

  • Apache 2.4版。 37

  • 在上述更改之前,所有这些标头都在 .htaccess 中起作用。据我所知,这不是 标头语法。

  • Apache version 2.4.37
  • All of these headers work in the .htaccess prior to the above changes. It's not Header syntax as far as I can tell.

任何帮助我们都会感激不尽。

Any help gratefully received.

推荐答案

经过大量探索,我发现发生这种情况的原因是由于PHP是通过CGI处理程序运行的。更改为 suphp 处理程序可立即解决此问题。

I found after much exploring that the reason this occurred was due to PHP being run via a CGI handler. Changing to suphp handler immediately resolved this issue.

请参见此问题/ answer 此答案

这篇关于在httpd.conf中设置标题不会在.htaccess中设置标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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