1

I have a script for set some limitation on download host. this script give me some file(index.php|dl.php|config.php) that I have to put them on my download host. The script also has these htaccess codes:

Order allow,deny
Deny from All

<FilesMatch "^(index\.php)?$">
    Allow from All
</FilesMatch>

<FilesMatch "^(dl\.php)?$">
    Allow from All
</FilesMatch>

but my web server is NGINX. what rewrite code should I put in nginx.conf ? by the way, I'd like set limitation on vip folder mysomain.com/vip . and I put (index.php|dl.php|config.php)` on it.

2
  • Add all the information to the question (including your comment below) and add what you have already tried
    – Drifter104
    Dec 15, 2016 at 11:32
  • @Drifter104 I did it.tnx
    – Mohammad
    Dec 15, 2016 at 11:56

1 Answer 1

1

I used it and it finally works.

location ~ ^(index\.php)?$ {
allow all;
}
location ~ ^(dl\.php)?$ {
allow all;
}
location /vip {
    deny all;
}

PS: I had some problems with these codes again. So I changed them to:

error_page 500 /index.php?error=500;
error_page 404 /index.php?error=404;
error_page 403 /index.php?error=403;
location /vip {
  internal;
  alias /home/mydirecadmin ACC /domains/dl1.mydomain.com/public_html/vip;
}

But I want to know, is it secure? how can I set a restriction for all files and folders within the VIP folder except dl and index.php?

4
  • 1
    Thanks for the feedback. Although this protects the /vip directory, it doesn't appear to do the same as the .htaccess code you posted. The .htaccess code blocks all files except for the two exceptions. In the Nginx code, the first two location blocks look superfluous?
    – MrWhite
    Dec 15, 2016 at 13:37
  • 1
    You might want to take a look at digitalocean.com/community/tutorials/… and check exactly how nginx will match the locations. This might break other things for you
    – Drifter104
    Dec 15, 2016 at 14:00
  • 1
    You don't need the parentheses in your location regex matches, since you aren't using them anywhere. So you should use location ~ ^index.php$ instead. Dec 15, 2016 at 21:18
  • @w3dk can you convert my htaccess to nginx code? how can I protect VIP folder except dl and index?
    – Mohammad
    Dec 17, 2016 at 20:23

Not the answer you're looking for? Browse other questions tagged .