了防止一些可能出現存在漏洞的後台腳本暴露
使用apache的htpasswd工具生成密碼
yingouqlj@yingouqlj
Adding password for user ******
nginx可以為網站或目錄甚至特定的文件設置密碼認證
格式為
site_pass為密碼文件
如果你輸入htpasswd命令提示沒有找到命令時
如果是為了給網站加上認證
如果是為了給目錄加上認證
例如
listen
server_name ;
root /www/akii;
index inde index
auth_basic "input you user name and password";
auth_basic_user_file /usr/local/nginx/conf/vhost/nginx_passwd;
location ~
fastcgi_pass
fastcgi_index index
include fastcgi_params;
}
location ~ /
deny all;
}
access_log /logs/akii
}
針對目錄的認證
listen
server_name ;
root /www/akii;
index inde index
location ~ ^/admin/
location ~
fastcgi_pass
fastcgi_index index
include fastcgi_params;
}
auth_basic "auth";
auth_basic_user_file /usr/local/nginx/conf/vhost/auth/admin
}
location ~
fastcgi_pass
fastcgi_index index
include fastcgi_params;
}
location ~ /
deny all;
}
access_log /logs/akii
}
這裡有一個細節
附一個可用的bash腳本 用於創建密碼
代碼如下 復制代碼 #!/bin/bashPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#set UserName
username=""
read
if [ "$username" = "" ]; then
echo "Error:UserName can
exit
fi
echo "==========================="
echo "UserName was: $username"
echo "==========================="
#set password
unpassword=""
read
if [ "$unpassword" = "" ]; then
echo "Error:Password can
exit
fi
echo "==========================="
echo "Password was: $unpassword"
echo "==========================="
password=$(perl
#set htpasswd file
htfile=""
read
if [ "$htfile" = "" ]; then
echo "Error:Auth filename can
exit
fi
echo "==========================="
echo "Auth File:$htfile"
echo "==========================="
get_char()
{
SAVEDSTTY=`stty
stty
stty cbreak
dd if=/dev/tty bs=
stty
stty echo
stty $SAVEDSTTY
}
echo ""
echo "Press any key to Creat
char=`get_char`
if [ !
echo "Create Auth file
cat >$htfile<<eof
$username:$password
eof
echo "Create Auth file successful
else
echo "File already exists
exit
fi
命令參數注釋:
Usage:
htpasswd [
htpasswd
htpasswd
htpasswd
From:http://tw.wingwit.com/Article/program/Java/gj/201404/30490.html