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; }
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
What’s the domain name?
thanks for the suggestion but it still doesn’t work.
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?