首页 > 解决方案 > X-Frame-Options 标头未设置为 nginx

问题描述

我的网站在 nginx 服务器上。我添加到 /etc/nginx/nginx.conf

add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;

标题未出现在网站上:

标题未出现在网站上

标签: nginxhttp-headersx-frame-optionsx-content-type-options

解决方案


我们需要更多关于您的nginx.conf文件的信息,但您可以将此指令添加到您的server块中:

server {
    
    listen 80;
    server_name example.com;

    add_header X-Frame-Options SAMEORIGIN;
    add_header X-Content-Type-Options nosniff;

    # ...
}

可能位于/etc/nginx/sites-enabled/example.com/etc/nginx/conf.d/example.com.conf

http块中所示/etc/nginx/nginx.conf

http {
    
    # ...

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

推荐阅读