Score:0

Inheriting rules from nginx.conf

jp flag

I am running multiple websites under the same nginx server using separate .conf files in the conf.d/ folder. However, to restrict access to certain secure files and folders, I have to enter the below lines in each .conf file

        # deny access to .htaccess files
        location ~ /\.ht {
            deny  all;
        }
           
        # restrict access to individual files
        location ~ /(composer\.lock|composer\.json|\.env|composer\.phar|channel\.xml|package\.xml) { return 403; }

        # restrict access to directories
        location ~* /(\.git|\.svn|db|protected)/.*$ { return 403; }

Is there any way I can enter this line in nginx.conf and have it universally apply to all virtual hosts?

Richard Smith avatar
jp flag
No. `location` blocks are not inherited. You could place these statements into a separate file and `include` them into each `server` block - which would be easier to maintain, but would still require you to have at least one line repeated in every `server` block.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.