By m73mitchell
Hi, I’m trying to implement HTTP authentication as outlined in this article https://www.digitalocean.com/community/articles/how-to-set-up-http-authentication-with-nginx-on-ubuntu-12-10
I went through the early steps in the tutorial where it prompts you to create a password. That was fine. I then added the two auth_basic and auth_basic_user_file lines to the second location block in my nginx.conf (see below) and pushed it to my server (which necessarily restarts the server), but the http authentication isn’t happening. I can access my demo rails app without problem.
Any ideas what I might be doing wrong? Thanks if you can help
upstream unicorn { server unix:/tmp/unicorn.remotepg.sock fail_timeout=0; }
server { listen 80 default deferred;
root /home/michael/apps/remotepg/current/public;
location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; }
try_files $uri/index.html $uri @unicorn; location @unicorn { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unicorn; auth_basic “Restricted”; auth_basic_user_file /home/michael/apps/remotepg/current/public/.htpasswd; }
error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; }
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!
Move these two lines <br> <br><pre>auth_basic “Restricted”; <br>auth_basic_user_file /home/michael/apps/remotepg/current/public/.htpasswd; </pre> <br> <br>inside a <pre> location / { <br>}</pre> block. Restart nginx, does that work?
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.