Skip to content
Dr. Thomas Jansen edited this page Aug 9, 2023 · 3 revisions

Preventing Git repository exposure in nginx

If you are using the nginx HTTP server, add the following location directive to your nginx.conf file:

location ~ /\.git {
    deny all;
}

If you want to return a 404 HTTP status code instead of 403, use the following instead:

location ~ /\.git {
    return 404;
}

Don't forget to restart nginx after making the change, e.g. on Debian:

sudo systemctl restart nginx
Clone this wiki locally