Sometimes you may need to remove ETag header from your website’s server response. In this article, we will look at how to disable ETag in NGINX.
What is ETag?
ETag is a server response header that allows browsers to do cache validation efficiently and make conditional requests. However, it poses security risks in case it gets leaked by your code, and result in cache poisoning attack on your website.
How To Disable ETag in NGINX
It is very easy to disable ETag in NGINX. We just need to set etag server variable to on/off to enable/disable ETag in NGINX.
1. Open NGINX configuration
Open terminal and run the following command to open NGINX configuration file.
$ sudo vi /etc/nginx/nginx.conf
If you have configured separate virtual hosts for your website (e.g www.example.com), such as /etc/nginx/sites-enabled/example.conf then open its configuration with the following command
$ sudo vi /etc/nginx/sites-enabled/example.conf
Also read : How to Enable HTTP/2 in NGINX
2. Disable ETag header
Add “etag off” to http, server or location blocks to disable ETag across all websites on your server, a specific website, a specific URL location respectively.
Adding etag off to http block will disable ETag for all servers running on your NGINX server.
http { ... etag off; ... }
Also read : How to Fix NGINX 413 Request too large error
Adding etag off to server block will disable ETag only for that server. For example, the following configuration will disable ETag only for server hosting example.com domain
server { listen 80; server_name example.com; etag off; ... }
Adding etag off to location block will disable ETag only for that location. For example, the following configuration will disable ETag only for /product location
location /product { ... etag off; ... }
Also read : How to Remove WWW from domain URL in NGINX
3. Restart NGINX Server
Finally, run the following command to check syntax of your updated config file.
$ sudo nginx -t
If there are no errors, run the following command to restart NGINX server.
$ sudo service nginx reload #debian/ubuntu $ systemctl restart nginx #redhat/centos
Use a third-party tool to check if your server response still contains ETag header.
Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it today!