Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

NGINX configuration folder protection of thousands of subdirectories

$
0
0
The following code allows me to protect a specific folder with the membership software we're using. The problem is if we have 1,000 folders we need to protect, we need to copy/paste this same code for each and every folder.

I'm wondering, how can I change the "location ^~ /FOLDER/" location so it encompasses every folder with the parent folder we want, and the "FOLDERID" so that it encompasses every number? (1 through infinite)

location ^~ /FOLDER/ {
if ($cookie_amember_nr !~* [a-zA-Z0-9]+) { #not authorized
rewrite ^(.*)$ http://EXAMPLE.COM/AMEMBER/protect/new-rewrite?f=FOLDERID&url=$request_uri?$args redirect;
}
set $file $document_root/AMEMBER/data/new-rewrite/$cookie_amember_nr-FOLDERID;
if (!-f $file) { #have not access
rewrite ^(.*)$ http://EXAMPLE.COM/AMEMBER/no-access/folder/id/FOLDERID?url=$request_uri?$args redirect;
}
#everything is ok
}

FOLDER with actual path to your protected folder
http://EXAMPLE.COM/AMEMBER with your actual aMember installation url
/AMEMBER/ with path to aMember installation on your server
FOLDERID with ID (integer value) for this folder in aMember CP



Example:

location ^~ /protect-folders/folder-1/ {
if ($cookie_amember_nr !~* [a-zA-Z0-9]+) { #not authorized
rewrite ^(.*)$ http://stackexamples.com/amember/protect/new-rewrite?f=513&url=$request_uri?$args redirect;
}
set $file $document_root/amember/data/new-rewrite/$cookie_amember_nr-513;
if (!-f $file) { #have not access
rewrite ^(.*)$ http://stackexamples.com/amember/no-access/folder/id/513?url=$request_uri?$args redirect;
}
#everything is ok
}

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>