Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

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!
This took me ages to figure out using Rails/Unicorn as all documentation for Rails/Unicorn online I found showed location like:
location @unicorn
I had to switch that to just
location /
Then it worked like a charm. Before the http auth settings were just ignored.
In case you don’t want to install apache2-utils you could always use an online generator like http://www.htaccesstools.com/htpasswd-generator/ to encrypt the password.
Of course it’s not as safe so think through your use case. :)
I found this tutorial useful, just wanted to add that in some cases you may want to prevent this Authorization header from being proxied upstream; in which case you should add (where appropriate to your needs):
# do not relay basic auth header
proxy_set_header Authorization "";
Keep in mind placing the auth_basic directives within a location block will make the HTTP authentication only active for that particular location.
This could be not what was intended, especially in dynamic site configurations (e.g. Drupal, WordPress) where multiple location statements may exist.
You can place the auth_basic directives directly in the server block to make it valid for the entire virtual host.
The author of Nginx is Igor Sysoev (http://en.wikipedia.org/wiki/Igor_Sysoev), please correct the typo.
If you want to password protect a subfolder, here is what I found out by following this guide - see section 3 - https://www.howtoforge.com/basic-http-authentication-with-nginx
Create a location block starting with “location /this/subfolder/path” For example:
location /this/subfolder/path {
auth_basic "Restricted";
auth_basic_user_file /var/www/domain/current/public//this/subfolder/path/.htpasswd;
}
Don’t forget to reload the nginx.config
Digital Ocean has very accurate clear and clean instructions that work, thanks!