How to disable Etag on Nginx

Endrit Qerreti

Endrit Qerreti

In this tutorial, you will learn how to disable Etag headers on your Nginx server.

Etag is simply a reponse header that is used for caching purposes. Whenever you visit a site if the Etag header is on , you may see it in the response of the request, this header is used to identify specific versions of the site/resources that you are visiting.

So if you visit a site for the first time, the site will get cached, and if the Etag header is on, then you will get the same Etag response on each visit, instead of serving a new resource, as the result will get cached and assigned to your Etag.

If the server has a new resource to serve, then it will check and compare the Etag header, if your Etag header is the same as the Etag header on the server, then you will be served the same resource. If Etag header is different, then you will be served a new resource and a new Etag header.

Disabling the Etag header is quite simple, and it can be done easily by setting etag to off on your nginx configuration file.

Step 1 - Open nginx.conf

nginx.conf is the file that contains your nginx configuration.

The Etag header can be easily disabled by setting the etag header to off on your nginx configuration file

First, open nginx.conf using nano text editor, or any text editor you like.

sudo nano /etc/nginx/nginx.conf

Step 2 - Turn off Etag Header

Once nginx.conf is opened in your terminal, you can now proceed to disable the etag header.

To do so, simply set the etag header to off.

The configuration should look like this.

server {

etag off;

}

In the config above we are disabling the Etag header for a single site on our server.

Depending on your setup, you can disable the Etag header for the whole server or only for a single site if you have multiple sites on your Nginx server.

For example, if you want to disable the Etag header for all sites on your server, then you need to disable Etag on the http block on your nginx configuration file nginx.conf.

http {

etag off;

}

Step 3 - Restart Nginx

Etag header should be now disabled on your nginx configuration file nginx.conf. All you have to do now is check if your nginx configuration file is configured correctly, and then simply restart.

To check if your nginx configuration file is configured correctly, run the command below.

sudo nginx -t

If your nginx configuration file is configured correctly, then proceed to restart your Nginx server.

Nginx can be easily restarted by using the restart command.

To do so, run the command below.

sudo systemctl restart nginx

💡
Note: If you are making changes on your production website, and you don't want to reboot your server, you can use the reload function.

sudo nginx reload

Conclusion

In this tutorial, you learned how to disable the Etag header response on Nginx server.

Now the Etag header should be disabled on your server.