I have tried to add following config to nginx.conf.
Access to http://ip_address:port/.git is forbidden, while http://ip_address:port/.git/config is still accessible.
server {
location ~ /\.git
{
deny all;
}
}
I have tried to add following config to nginx.conf.
Access to http://ip_address:port/.git is forbidden, while http://ip_address:port/.git/config is still accessible.
server {
location ~ /\.git
{
deny all;
}
}
You need to anchor the expression to the beginning of the URI with ^:
server {
# Deny any URI beginning with /.git
location ~ ^/\.git { deny all; }
}
You can also achieve the same without regex at all:
server {
# Deny any URI beginning with /.git
location /.git { deny all; }
}
Using regex makes more sense when you want a general pattern, for example a location for gif, jpg, and jpeg files:
server {
location ~* \.(gif|jpg|jpeg)$ {
# some cache settings
}
}