Hey @Mamaduka,
The example above will only work on Linux. Here’s how you can configure Basic Auth on macOS with Local Lightning.
-
Use
htpasswd
to add a user to an.htpasswd
file in the site’sapp
directory. Example command (be sure to adjust the path to the site and changeEXAMPLE_USER
):htpasswd -c ~/Local\ Lightning\ Sites/basic-auth/app/.htpasswd EXAMPLE_USER
-
Add the following to the site’s
conf/nginx/includes/wordpress-single.conf.hbs
right before thetry_files
directive (editwordpress-multi.conf.hbs
if the site is multisite)auth_basic "Please log in"; auth_basic_user_file /PATH/TO/SITE/app/.htpasswd;
So, for me,
conf/nginx/includes/wordpress-single.conf.hbs
becomes…# WordPress single blog rules. # Designed to be included in any server {} block. # This order might seem weird - this is attempted to match last if rules below fail. # http://wiki.nginx.org/HttpCoreModule location / { auth_basic "Please log in"; auth_basic_user_file "/Users/claygriffiths/Local Lightning Sites/basic-auth/app/.htpasswd"; try_files $uri $uri/ /index.php$is_args$args; } # Add trailing slash to */wp-admin requests. rewrite /wp-admin$ $resolved_scheme://$host$uri/ permanent;
-
Restart the site so the config takes effect