Now that I have nginx setup I need to be able to hide my .git
directories. What kind of rewrite would I need to stop prying eyes? And where in the server {}
or http {}
block would it go?
现在我有了nginx设置,我需要能够隐藏我的.git目录。我需要怎样的重写才能停止窥探?在服务器{}或http{}块中,它会去哪里?
3 个解决方案
#1
61
http {
server {
location ~ /\.git {
deny all;
}
}
}
This location
directive will deny access to any .git
directory in any subdirectory.
此位置指令将拒绝访问任何子目录中的任何.git目录。
Note: This location block must be before your main location block, so that it can be evaluated first.
注意:此位置块必须位于主位置块之前,以便首先对其进行计算。
#2
43
Hidden directories and files should never be web accessible. The general answer to your question is:
隐藏目录和文件不应该是可访问的。你的问题的一般回答是:
location ~ /\. { return 403; }
This denies access to .git, .svn, .htaccess and similar files in any subdirectory.
这将拒绝访问任何子目录中的.git、.svn、.htaccess和类似文件。
#3
1
This will prevent someone from hitting the http://example.com/.git but if your working in a subdirectory like this http://example.com/example/.git it will fail. You really need:
这将防止有人访问http://example.com/.git,但是如果您在类似于http://example.com/example/.git的子目录中工作,那么它将失败。你真正需要的:
location ~ .*/\.git {
deny all;
}
#1
61
http {
server {
location ~ /\.git {
deny all;
}
}
}
This location
directive will deny access to any .git
directory in any subdirectory.
此位置指令将拒绝访问任何子目录中的任何.git目录。
Note: This location block must be before your main location block, so that it can be evaluated first.
注意:此位置块必须位于主位置块之前,以便首先对其进行计算。
#2
43
Hidden directories and files should never be web accessible. The general answer to your question is:
隐藏目录和文件不应该是可访问的。你的问题的一般回答是:
location ~ /\. { return 403; }
This denies access to .git, .svn, .htaccess and similar files in any subdirectory.
这将拒绝访问任何子目录中的.git、.svn、.htaccess和类似文件。
#3
1
This will prevent someone from hitting the http://example.com/.git but if your working in a subdirectory like this http://example.com/example/.git it will fail. You really need:
这将防止有人访问http://example.com/.git,但是如果您在类似于http://example.com/example/.git的子目录中工作,那么它将失败。你真正需要的:
location ~ .*/\.git {
deny all;
}