Deny Access to .git and .svn folders with NGINX

OS type and version Debian 10
Virtualmin version 7-04

Hi community,

I have a question. Meanwhile I’m playing a little bit around with NGINX.
What I want to do is denying access to the .git and .svn folders.
Since on Apache it’s pretty simple to do that serverwide by modifying the httpd.conf, is there a way to do that on NGINX as well?
Haven’t found any good solution yet to do that. In my preference it would be nice to do that as well serverwide.
Maybe someone can give me a hint?

Thanks a lot

Maybe @Ilia knows a trick? :grinning:

Perhaps, adding to your server {} config, as the very last block, using Webmin / Servers ⇾ Nginx Webserver: Edit Configuration Files page something like:

location ~ /(\.git|\.svn) {
   	deny all;
   	return 404;

… and restarting Nginx manually.

1 Like

Awesome, thanks a lot Ilia

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.