Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在docker容器中禁用对/.git/config文件的访问_Git_Docker_Nginx - Fatal编程技术网

如何在docker容器中禁用对/.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 ~ ^

我尝试将以下配置添加到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 ~ ^/\.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
  }
}