[root@wjh2 ~]# htpasswd -c /usr/local/nginx/conf/.htpasswd test
#用apache下的hptasswd命令生成密码,apaceh有详解#
New password:
Re-type new password:
Adding password for user test
[root@wjh2 ~]# vi /usr/local/nginx/conf/vhosts/discuz.conf #打开虚拟主机配置文件#
加入以下配置:
server
{
listen 80; #监听端口#
server_name www.123.com ; #访问域名#
index index.html index.htm index.php;
root /discuz/www; #网站根目录#
#用户认证
location ~ .*admin\.php$ { #匹配admin.php访问是discuz管理后台#location / 匹配全站 location /aming/ 匹配目录
auth_basic "qing zhu yi an quang"; #提示信息,可随便自定义#
auth_basic_user_file /usr/local/nginx/conf/.htpasswd; #指定创建用户密码路径#
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /discuz/www$fastcgi_script_name;
}
location ~ \.php$ {
include fastcgi_params;
#fastcgi_pass unix:/tmp/php-fcgi.sock
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /discuz/www$fastcgi_script_name;
}
}
[root@wjh2 www]# service nginx configtest #检查配置文件有没有错误#
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
[root@wjh2 www]# service nginx reload #重新加载配置文件#
重新载入 Nginx: [确定]