Preventing public access to .git directory

Hi there, we need to prevent public access to our .git directory on our EE server.

It is suggested that we update our configuration file with the following:

 location ~ path/to/our-repo/.git {
        deny  all;

We are however unsure where to place this in our configuration file – would it be in the block for that specific site or as a general rule?

Would this go in /etc/nginx/nginx.conf or in /etc/nginx/sites-available/ ?

Any help would be greatly appreciated.

Kind regards Francois Wessels


That’s the right place for such code.

Thank you @portofacil , ammended as suggested :slight_smile:

Kind regards @francois_wessels