Applicable to:
- Plesk for Linux
Question
How to allow access to the website directory from specified IP address only using
.htaccess
file?
Answer
There are few ways of achieving this.
Through Plesk:
- If nginx reverse proxy is used(check Tools & Settings > Services Management):
- Navigate to Domains > example.com > Apache & nginx Settings;
- Add the following text to Additional nginx directives:
CONFIG_TEXT: location ^~ /directory {
allow 203.0.113.2;
deny all;
}
-
If nginx reverse proxy is not used:
- Navigate to Domains > example.com > Apache & nginx Settings;
- Add the following text to Additional Apache directives:
CONFIG_TEXT: <Location "/directory">
Order Deny,Allow
Deny from all
Allow from 203.0.113.2
</Location>
Through the website directly:
-
Connect to the server via SSH.
-
Create
.htaccess
file in the directory required to be protected with the following content:CONFIG_TEXT: <IfModule mod_authz_host.c>
<RequireAll>
Require ip 203.0.113.2
</RequireAll>
</IfModule>Also make sure that the
authz_host_module
is installed on your server by executing the following command:# httpd -M | grep authz_host
Note:
authz_host_module (shared).htaccess
file should be placed in the directory required to be protected.
Comments
0 comments
Please sign in to leave a comment.