Answer the question
In order to leave comments, you need to log in
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;
}
Answer the question
In order to leave comments, you need to log in
I think something like this:
location ~* /admin/(.+)\.txt$ {
access_log off;
return 403;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question