繁体   English   中英

如何将“X-Content-Type-Options: nosniff”添加到来自我的 Web 服务器的所有响应标头

[英]How can I add “X-Content-Type-Options: nosniff” to all the response headers from my web server

我正在运行一个 apache 网络服务器。 我想将“X-Content-Type-Options: nosniff”添加到来自我的 Web 服务器的所有响应标头中。 我怎样才能做到这一点? 是否可以更改 apache 配置文件来完成此操作?

在确保加载 mod_headers 后,只需将其附加到您的网络服务器配置中:

<Directory "your_web_server_documents_directory">
    .......
    Header always set X-Content-Type-Options nosniff
    .......
</Directory>

我所做的是这个。 我在注释掉属性 modules/mod_headers.so 后立即放置标签并重新启动我的应用程序服务器,但仍然是相同的响应标头。

LoadModule headers_module modules/mod_headers.so

<Directory mod_headers.c>
     Header always set X-Content-Type-Options nosniff
</Directory>

打开您的 .htaccess 并将其放入以防止 XSS、点击劫持和内容嗅探:

# Extra Security Headers
<IfModule mod_headers.c>
    Header set X-XSS-Protection "1; mode=block"
    Header always append X-Frame-Options SAMEORIGIN
    Header set X-Content-Type-Options nosniff
</IfModule>

参考: https : //htaccessbook.com/increase-security-x-security-headers

如果其他答案对您不起作用,则可能是该路径中不存在 headers 模块。 尝试通过在服务器的命令行中运行以下命令来简单地启用它:

a2enmod headers

然后编辑您的配置文件sudo nano /etc/apache2/apache2.conf找到以<Directory /var/www/><Directory /srv>开头的行,并在其中添加以下内容:

<IfModule mod_headers.c>
   Header always set X-Content-Type-Options nosniff
</IfModule>

记住之后重新启动 apache,以便进行更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM