Skip to content

Protect folder on NGINX (aMember Remote)

NGINX does not process .htaccess files, so aMember Remote cannot install folder-protection rules automatically. Configure the folder and its allowed products in aMember Remote first, then add the corresponding rule to the NGINX server block for the protected website.

location ^~ /FOLDER/ {
# Redirect visitors who do not have an aMember Remote session.
if ($cookie_amember_nr !~* "^[a-zA-Z0-9]+$") {
return 302 https://EXAMPLE.COM/AMEMBER-REMOTE?products=PRODUCTID&url=$request_uri;
}
set $access_file $document_root/AMEMBER-REMOTE/data/new_rewrite/$cookie_amember_nr-PRODUCTID;
# Redirect visitors whose session does not grant access to the product.
if (!-f $access_file) {
return 302 https://EXAMPLE.COM/AMEMBER-REMOTE?products=PRODUCTID&url=$request_uri;
}
}

Replace the placeholders as follows:

  • FOLDER — URL path of the protected folder, relative to the website root.
  • https://EXAMPLE.COM/AMEMBER-REMOTE — public URL of the aMember Remote installation.
  • /AMEMBER-REMOTE — URL path of aMember Remote below the same NGINX document root. The rule prepends $document_root when it checks the access file.
  • PRODUCTID — numeric ID of the product that grants access.

Use the following rule when access to either product is sufficient:

location ^~ /FOLDER/ {
if ($cookie_amember_nr !~* "^[a-zA-Z0-9]+$") {
return 302 https://EXAMPLE.COM/AMEMBER-REMOTE?products=PRODUCTID1,PRODUCTID2&url=$request_uri;
}
set $access_file1 $document_root/AMEMBER-REMOTE/data/new_rewrite/$cookie_amember_nr-PRODUCTID1;
set $access_file2 $document_root/AMEMBER-REMOTE/data/new_rewrite/$cookie_amember_nr-PRODUCTID2;
set $has_access 0;
if (-f $access_file1) {
set $has_access 1;
}
if (-f $access_file2) {
set $has_access 1;
}
if ($has_access = 0) {
return 302 https://EXAMPLE.COM/AMEMBER-REMOTE?products=PRODUCTID1,PRODUCTID2&url=$request_uri;
}
}

Replace PRODUCTID1 and PRODUCTID2 with the two product IDs. Add another access-file variable and file check for each additional product.

Run nginx -t to validate the configuration. If the test succeeds, reload NGINX to apply the changes.