O
O
Onotolius2018-06-30 17:55:15
Nginx
Onotolius, 2018-06-30 17:55:15

How to deny access to files in a folder in nginx?

Hello dear experts.
In general, I have a folder /admin/ and it contains txt files as well as index.php.
It is necessary to forbid access to txt files, but for index.php to be available.
So that I can type site.com/admin/ in the browser and get into my admin panel.
None of the options below work

location ~* /admin/$ {
try_files $uri $uri/ =404;
}

location ~* /admin/ {
access_log off;
return 403;
}

...
location ~* /admin/ {
location ~* /admin/$ {
try_files $uri $uri/ =404;
}
access_log off;
return 403;
}

...
location ~* /admin/ {
if ( $uri ~* "(.+)\.txt$" ) {
access_log off;
return 403;
}
}

...
location ~* /admin/ {
if ( $uri ~* "(.+)\.txt$" ) {
access_log off;
return 403;
}
try_files $uri $uri/ =404;
}

How to find the right solution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2018-07-01
@2ord

I think something like this:

location ~* /admin/(.+)\.txt$ {
access_log off;
return 403;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question