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

Above snippet should be placed inside “server” block

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *