nginx deny directory and files to be downloaded

11,728

You can deny specific file types using

location ~* \.(git|rb|inc|ht)$ {
    deny all;
}
Share:
11,728

Related videos on Youtube

YeppThat'sMe
Author by

YeppThat'sMe

Updated on September 18, 2022

Comments

  • YeppThat'sMe
    YeppThat'sMe almost 2 years

    gurus. I have a problem and i dont know how to solve it. I am working with Git and Compass/SASS on some projects. Now i want to protect those directories. When i go only to the folder its all fine – i get what i expected a 403 forbidden.

    location ~ /\.git {
            deny all;
    }
    

    But when i try use the full path to the config file from git the browser start to download it. Same scenario with compass. There is a config.rb file within the folder which also starts to download it. How can i prevent this behaviour?

    How can i deny downloading specific files?

  • YeppThat'sMe
    YeppThat'sMe over 10 years
    Will this prevent files being downloaded?
  • Ali Gajani
    Ali Gajani over 8 years
    How does this work if I am talking about a specific folder where these files are?
  • Fernando Paladini
    Fernando Paladini over 6 years
    It worked for me!