How do you hide .git project directories?

Now that I have nginx installed, I need to hide my .git directories. Which rewrite do I need to stop prying eyes? And where in the server {} or http {} block will it go?

+45
git regex nginx
Jun 08 2018-10-06T00:
source share
3 answers
 http { server { location ~ /\.git { deny all; } } } 

This location directive will deny access to any .git directory in any subdirectory.

Note. This location block must be before your main location block so that it can be evaluated first.

+61
Jun 08 '10 at 17:26
source share

Hidden directories and files should never be available on the Internet. General answer to your question:

  location ~ /\. { return 403; } 

This prohibits access to .git, .svn, .htaccess files and similar files in any subdirectory.

+43
Sep 15 '13 at 16:50
source share

This will not allow anyone to click http://example.com/.git , but if you work in a similar subdirectory http://example.com/example/.git , this will not work. You really need to:

 location ~ .*/\.git { deny all; } 
+1
Jul 23 '13 at 20:34
source share



All Articles