August 2017
Intermediate to advanced
278 pages
8h 53m
English
If we want to simply lock down a specific location, we can do this as well. Consider this example where we take the server block directive from the Configuring NGINX for WordPress recipe in Chapter 2, Common PHP Scenarios and add additional authentication to the wp-admin directory and wp-login.php location:
location ~ ^(/wp-login.php|/wp-admin/) {
auth_basic "Restricted Area";
auth_basic_user_file /var/www/private/.htpasswd;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
The configuration matches any request starting with (as denoted by the ^ symbol) either /wp-login.php or (|) /wp-admin/ ...
Read now
Unlock full access