0

I'm using NGINX to run a wordpress membership site, where I need to restrict access to specific files and memberships, but in order for this to work I must add the following rules to .htaccess:

 RewriteCond %{REQUEST_URI} !^/(wp-content/themes|wp-content/plugins|wp-admin|wp-includes) RewriteCond %{REQUEST_URI} \.(mp3|mp4|avi|pdf|zip|rar|doc|gz|tar|docx|xls|xlsx|PDF) RewriteRule . /index.php?ihc_action=check-file-permissions [L] 

But of course .htaccess doesn't exist since I'm not using APACHE.

So I converted the .htaccess rules to nginx.conf directives:

 location ~ \.(mp3|mp4|avi|pdf|zip|rar|doc|gz|tar|docx|xls|xlsx|PDF)$ { # Check if the URI does NOT start with the excluded paths if ($request_uri !~ ^/(wp-content/themes|wp-content/plugins|wp-admin|wp-includes)) { rewrite ^ /index.php?ihc_action=check-file-permissions last; } # If it does start with an excluded path, or if it doesn't match the file extensions # (though the location block already handles file extensions), # then let Nginx try to serve the file normally. # This try_files is a fallback for when the 'if' condition is false. try_files $uri $uri/ /index.php?$args; } 

Unfortunately it doesn't work

Any ideas?

7
  • 2
    WHAT doesn't work? Commented Jun 19 at 9:00
  • File access restriction works on APACHE and mentioned .htaccess rules, but not on NGINX with nginx.conf converted rules. Commented Jun 19 at 10:15
  • "I suggest you use Apache as the backend server at any other port, which will run WordPress, and use NGINX as a reverse proxy to serve requests. That's the way to use .htaccess with NGINX." Commented Jun 19 at 10:23
  • Thanx for your reply Commented Jun 19 at 10:30
  • 1
    Please add full nginx configuration to the question as shown by nginx -T command. This configuration snippet alone isn't enough to find the reason. Commented Jun 21 at 10:50

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.