Block access to.git folder in nginx

How to Block access to .git folder in nginx?

If you have your code in a git Repository and you are cloning that repository on your nginx root directory, it is critical to block access to the .git folders in nginx. If not done, anyone can access .git folder and its a security risk. You can block access to the .git folder by adding following in your nginx configuration files

1 2 3 4 5   location ~ /\.git {   deny all; }  

Above snippet should be placed inside “server” block

Same code will work with .svn folders also, just you have to replace “git” with “svn”.

1 2 3 4 5   location ~ /\.svn {   deny all; }  

Don’t forget to restart nginx after making changes in configuration ????

Author: , 0000-00-00