English English French French Spanish Spanish German German
Geekflare is supported by our audience. We may earn affiliate commissions from buying links on this site.
Share on:

Secure Apache & Nginx MIME types with X-Content-Type-Options nosniff

https redirection
Invicti Web Application Security Scanner – the only solution that delivers automatic verification of vulnerabilities with Proof-Based Scanning™.

X-Content-Type-Options Header Implementation in Apache, Nginx, IBM HTTP Server & Shared Hosting

Every resource served from a web server is associated with MIME type (also called content-type).

There is a possibility to execute style sheet and steal content from another site through content type doesn’t match. You may prevent this vulnerability in Internet Explorer or Google Chrome by adding nosniff in the header.

In this quick guide, I will explain how to add X-Content-Type-Options header in Apache HTTP, Nginx, IHS & Shared hosting to reduce MIME types attack risk.

Few things

  • Take a backup of an existing configuration file to restore if something goes wrong.
  • To verify the header response, you may use the HTTP Header Checker online tool.
  • If you are using cloud-based Security Protection like SUCURI, then you don’t have to worry, as this is already enabled by default.

Apache and IBM HTTP Server

  • Modify the httpd.conf file and ensure mod_headers.so is enabled. The following line should be uncommented.
LoadModule headers_module modules/mod_headers.so
  • Add following parameter
Header set X-Content-Type-Options nosniff
  • Save the configuration file and restart Apache to take effects.

Here is how the header response looks like.

x-content-type-results

Nginx Web Server

  • Add the following parameter in nginx.conf under server block
add_header X-Content-Type-Options nosniff;
  • Save the nginx.conf file and restart Nginx to see the results.

Implementation in Shared Hosting

If you are using shared hosting like SiteGround or anyone who offers .htaccess file.

  • Login to your cPanel and go to File Manager
  • Modify .htaccess file and add the following
Header set X-Content-Type-Options nosniff
  • Save the file and refresh the page to see the results.

I hope this adds a layer of security to your site.

Thanks to our Sponsors
More great readings on Apache HTTP
Power Your Business
Some of the tools and services to help your business grow.
  • Invicti uses the Proof-Based Scanning™ to automatically verify the identified vulnerabilities and generate actionable results within just hours.
    Try Invicti
  • Web scraping, residential proxy, proxy manager, web unlocker, search engine crawler, and all you need to collect web data.
    Try Brightdata
  • Semrush is an all-in-one digital marketing solution with more than 50 tools in SEO, social media, and content marketing.
    Try Semrush
  • Intruder is an online vulnerability scanner that finds cyber security weaknesses in your infrastructure, to avoid costly data breaches.
    Try Intruder