[root@rhel6u3-2 ~]# uname –r //查看系统内核版本号
2.6.32-279.el6.i686
[root@rhel6u3-2 ~]# cat /etc/redhat-release //查看系统版本号
Red Hat Enterprise Linux Server release 6.3 (Santiago)
[root@rhel6u3-7 ~]# vim /usr/local/nginx/conf/nginx.conf //主配置文件中http字段中添加以下语句,将虚拟主机的配置文件指向www1.rsyslog.org
include /usr/local/nginx/server/www1.rsyslog.org;
[root@rhel6u3-7 ~]# vim /usr/local/nginx/server/www1.rsyslog.org
server {
listen 80; //监听端口为80
server_name www1.rsyslog.org; //虚拟主机网址
location / {
root sites/www1; //虚拟主机网站根目录
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"; }
}
[root@rhel6u3-7 server]# htpasswd -c /usr/local/nginx/passwd.db xiaonuo //创建认证信息,xiaonuo 为认证用户名
New password: ******* //输入认证密码
Re-type new password: ******** //再次输入认证密码
Adding password for user xiaonuo
[root@rhel6u3-7 server]#
[root@rhel6u3-7 ~]# chmod 400 /usr/local/nginx/passwd.db //修改网站认证数据库权限
[root@rhel6u3-7 ~]# chown nginx. /usr/local/nginx/passwd.db //修改网站认证数据库属主和属组
[root@rhel6u3-7 ~]# cat /usr/local/nginx/passwd.db //可以看到通过htpasswd生成的密码为加密格式
xiaonuo:8eZAz7BqcrXmY
[root@rhel6u3-7 ~]#
[root@rhel6u3-7 ~]# /etc/rc.d/init.d/nginx reload //平滑重启nginx服务
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Reloading nginx: [ OK ]
www1 A 192.168.100.107
本文出自 “小诺的Linux开源技术博客” 博客,请务必保留此出处http://dreamfire.blog.51cto.com/418026/1141385