[root@wjh2 ~]# htpasswd -c /usr/local/nginx/conf/.htpasswd testphp
#用apache下的hptasswd命令生成密码,apaceh有详解#html
New password:nginx
Re-type new password:apache
Adding password for user test网站
[root@wjh2 ~]# vi /usr/local/nginx/conf/vhosts/discuz.conf #打开虚拟主机配置文件#unix
加入如下配置:server
serverhtm
{ip
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: [肯定]