如何在docker容器中禁用对/.git/config文件的访问
我尝试将以下配置添加到nginx.conf 获取http://ip_address:port/.git 是禁止的,而http://ip_address:port/.git/config 仍然可以访问如何在docker容器中禁用对/.git/config文件的访问,git,docker,nginx,Git,Docker,Nginx,我尝试将以下配置添加到nginx.conf 获取http://ip_address:port/.git 是禁止的,而http://ip_address:port/.git/config 仍然可以访问 server { location ~ /\.git { deny all; } } 您需要使用^将表达式锚定到URI的开头: server { # Deny any URI beginning with /.git location ~ ^
server {
location ~ /\.git
{
deny all;
}
}
您需要使用
^
将表达式锚定到URI的开头:
server {
# Deny any URI beginning with /.git
location ~ ^/\.git { deny all; }
}
不使用正则表达式也可以实现同样的效果:
server {
# Deny any URI beginning with /.git
location /.git { deny all; }
}
当需要常规模式时,使用正则表达式更有意义,例如gif
、jpg
和jpeg
文件的位置:
server {
location ~* \.(gif|jpg|jpeg)$ {
# some cache settings
}
}