I’m trying to add basic auth for wp-login but it is not working
Here is the code I have added to /etc/nginx/sites-available/default file
location ^~ /wp-login.php {
auth_basic "Admin Login";
auth_basic_user_file /var/www/html/.htpasswd;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /wp-admin/admin-ajax.php {
allow all;
}
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi @bepari662,
I’m not sure if the location is actually correct. Can you try using :
location ~ ^/(wp-admin|wp-login\.php)
instead of
location ^~ /wp-login.php
The reason behind the non working basic auth is most probably as it doesn’t actually gets to the specified location.
Regards, KDSys
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.