Roots Discourse

NGINX htpasswd

I’m looking to implement a htpasswd prompt on my site.
Following the general lines of this Digital Ocean article currently, but part of the step is to create a file at: /etc/nginx

Therefore for me:

/trellis
vagrant ssh
cd /etc/nginx

Create the file here, or not? Because when deployed to my hosting, will the file be there or will the provision on production not have the file/wipe out any I create.

I have a need to passwd prompt any page on my site other than the homepage, looking to add:

location = / {
  // first location rule and specific using = means it takes priority
  // no htpasswd
}

location / {
  // catch-all rule for those paths not already matched
  // htpasswd
}

When you deploy the file will probably be left alone. When you provision, it will probably be overwritten or otherwise messed with.

I would recommend writing a Trellis role to build your password file on deploy. These roles would probably be a good starting point: https://github.com/roots/trellis/tree/master/roles/wordpress-setup/tasks

I love this and use it often.

What I couldn’t work out with this is, can you modify this to display a password prompt on certain pages.

@JordanC26 I’m curious if you found a solution. I have a similar need (password-protect a single file), and as you noted above the bedrock-site-protect plugin, while excellent, doesn’t handle targeting specific files/directories.

Unfortunately not @needle, it was a little beyond me creating a custom Trellis role as alwaysblank suggested. Maybe if I had time to focus on it, but I simply went without the password for now.

@JordanC26
Could you use the built in password protection that comes with WordPress for the publish status?

Yeah however wanted to try see if I could do it on mass, 20+ pages easily and quickly using something like the package above. Defining which pages do/don’t get password protected.

This topic was automatically closed after 42 days. New replies are no longer allowed.