首页 > 代码库 > nginx认证配置
nginx认证配置
?
rpm -qa|grep httpd-tools
yum install httpd-tools ###这样不仅可以使用ab工具,还可以使用htpasswd工具了
?
?
虚拟主机 ->>主配置里include extra配置即可
?
server {
listen 80;
server_name www.lanny.com;
location / {
root data/www;
index index.html index.htm;
auth_basic "secret";
auth_basic_user_file /usr/local/nginx/passwd.db;
}
location /status {
stub_status on;
access_log /usr/local/nginx/logs/www1_status.log;
auth_basic "NginxStatus"; }
}
?
?
创建密码文件:
htpasswd -c /usr/local/nginx/passwd.db lanny #首次要加-c 之后不需要加了.
chmod 400 /usr/local/nginx/passwd.db
chown nginx. /usr/local/nginx/passwd.db
cat /usr/local/nginx/passwd.db
?
nginx -t
/etc/rc.d/init.d/nginx -s reload
nginx认证配置