T
T
try4tune2013-05-23 13:12:40
Nginx
try4tune, 2013-05-23 13:12:40

Write a rule for location in nginx?

Good afternoon,
There is the following folder structure for the main host in nginx (/usr/share/nginx/www/):
install1/
-- app
-- config
-- data
install2/
-- app
-- config
-- data
installN/
-- app
-- config
-- data
other/
We need to write a rule for nginx that will block access to the app/ , config/ and data/ subfolders of each folder at the top level.
The current rule is this:
location ~* /app/ { deny all; }
but it blocks the app folder at any level, not just the second.
How to make the rule correct?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
avalak, 2013-05-23
@avalak

location ~ ^/install(\d+)/(app|config|data)/ {
    deny all;
}

~- case sensitive
^- the beginning of the line
(\d+)- one or more digits
(app|config|data)- matches app or config or data
Best of all, if this data is not available at all (it will be outside the webroot), then they will not have to be protected.

A
Andrey Burov, 2013-05-23
@BuriK666

location ~* ^/.*/app/ { deny all; }
like so

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question