nginx HTTP authentication

July 26, 2013 3.2k views
Hi, I'm trying to implement HTTP authentication as outlined in this article 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; # server_name; 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; }
3 Answers
Move these two lines

auth_basic "Restricted";

auth_basic_user_file /home/michael/apps/remotepg/current/public/.htpasswd;

inside a
 location / {

block. Restart nginx, does that work?
thanks for the suggestion but it still doesn't work.
What's the domain name?
Have another answer? Share your knowledge.