nginx配置用戶認證

[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: [肯定]

相關文章
相關標籤/搜索