Protect folder on NGINX (aMember Remote)
NGINX server do not have support for .htaccess files so aMember Remote can not protect folder automatically. You will need to add some configuration rules to your NGINX config file manually.
Here is rules that you need to add
location ^~ /FOLDER/ {
if ($cookie_amember_nr !~* [a-zA-Z0-9]+) { #not authorized
rewrite ^(.*)$ http://EXAMPLE.COM/AMEMBER-REMOTE?products=PRODUCTID&url=$request_uri redirect;
}
set $file $document_root/AMEMBER-REMOTE/data/new_rewrite/$cookie_amember_nr-PRODUCTID;
if (!-f $file) { #have not access
rewrite ^(.*)$ http://EXAMPLE.COM/AMEMBER-REMOTE?products=PRODUCTID&url=$request_uri redirect;
}
#everything is ok
}
In this code please replace
- FOLDER with actual path to your protected folder
- http://EXAMPLE.COM/AMEMBER-REMOTE with your actual aMember Remote installation url
- /AMEMBER-REMOTE/ with path to aMember Remote installation on your server
- PRODUCTID with ID (integer value) for this Product in aMember CP
Then restart NGINX.
In case of multiple products rule will look the following way:
location ^~ /FOLDER/ {
if ($cookie_amember_nr !~* [a-zA-Z0-9]+) { #not authorized
rewrite ^(.*)$ http://EXAMPLE.COM/AMEMBER-REMOTE?products=PRODUCTID1,PRODUCTID2&url=$request_uri redirect;
}
set $file1 $document_root/AMEMBER-REMOTE/data/new_rewrite/$cookie_amember_nr-PRODUCTID1;
set $file2 $document_root/AMEMBER-REMOTE/data/new_rewrite/$cookie_amember_nr-PRODUCTID2;
set $has_access = 0;
if (-f $file1) {
set $has_access = true;
}
if (-f $file2) {
set $has_access = true;
}
if ($has_access != true) { #have not access
rewrite ^(.*)$ http://EXAMPLE.COM/AMEMBER-REMOTE?products=PRODUCTID1,PRODUCTID2&url=$request_uri redirect;
}
#everything is ok
}