Search code examples
nginxhttp-headersx-frame-optionsx-content-type-options

X-Frame-Options header doesnt set to nginx


My site is on nginx server. Im add to the /etc/nginx/nginx.conf

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

The headers is not appear on the site:

The headers is not appear on the site


Solution

  • We need more about your nginx.conf file, but you can add this directives into your server block:

    server {
        
        listen 80;
        server_name example.com;
    
        add_header X-Frame-Options SAMEORIGIN;
        add_header X-Content-Type-Options nosniff;
    
        # ...
    }
    

    Maybe located at /etc/nginx/sites-enabled/example.com or /etc/nginx/conf.d/example.com.conf.

    As indicated in the http block in /etc/nginx/nginx.conf:

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