Nginx Password Protect 403 Forbidden -
i running centos 6 nginx. running perfectly, trying password protect admin directory.i can login. however, 403 forbbiden when try view main index page (index.php) in directory.
2013/04/18 02:10:17 [error] 17166#0: *24 directory index of "/usr/share/ngin/html /somedir/" forbidden, client: xxx, server: mysite.com, request: "get /somedir/ http/1.1", host: "mysite.com"
i have double checked permissions on ".htpasswd" file. belongs "root:root" chmod 640. have tried setting owner ship "nginx:nginx" , error still persists.
this how getting htpasswd working:
location ~ ^/([^/]*)/(.*) { if (-f $document_root/$1/.htpasswd) { error_page 599 = @auth; return 599; } } location @auth { auth_basic "password-protected"; auth_basic_user_file $document_root/$1/.htpasswd; }
though question pretty old, must put solution here others. problem pain in somewhere.
i have read out (and implemented/tried) possible threads available online (till date) none solved "403 forbidden" nginx issue all-together:
i write down steps beginning: ( block site access ):
1> create hidden file called .htpasswd in /etc/nginx
sudo sh -c "echo -n 'usernamee:' >> /etc/nginx/.htpasswd"
2> add encrypted password given username
sudo sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd"
this ask enter password , confirm it.
3> need setup nginx check our newly created .htpasswd before serving content.
location / { try_files $uri $uri/ /index.php?$query_string; # per configuration auth_basic "authorized access only"; auth_basic_user_file .htpasswd; }
4> restart server take effect
sudo service nginx restart
now browse url:
please note: didnt alteration in permissions. default file permission htpasswd set @ time of creation, this:
-rw-r--r-- 1 root root 42 feb 12 12:22 .htpasswd
Comments
Post a Comment