Make .git directory web inaccessible

后端 未结 9 1730
耶瑟儿~
耶瑟儿~ 2020-11-30 17:22

I have a website that I use github (closed source) to track changes and update site. The only problem is, it appears the .git directory is accessible via the web. How can I

9条回答
  •  孤城傲影
    2020-11-30 18:05

    I'm not comfortable with controlling access to my .git folders individually and choose to do it via apache config instead of .htaccess, to prevent me overwriting them, or forgetting on a new install etc.

    Here are some detailed instructions hope they help. I'm using Ubuntu 16.10.

    1. First check what happens if you navigate to the .git folder in a browser. In my case I was presented with a directory listing. If you are seeing what you shouldn't be seeing (ie. you're not getting a 404), do the following.
    2. Use apache2ctl -V to get the HTTPD_ROOT and SERVER_CONFIG_FILE
    3. Use this to edit your apache config, in my case $ sudo nano /etc/apache2/apache2.conf
    4. Add the following somewhere in the config file: RedirectMatch 404 /.git
    5. Restart apache: $ sudo service apache2 restart
    6. Should now get you a 404 if you navigate to the folder again
    7. I tried this with .gitignore and also got a 404

提交回复
热议问题