网站配置用户认证

2018-03-29

实现网站的认证访问需要指定用户文件。

1、yum -y install httpd安装,用htpasswd命令增加两个用户
htpasswd -c -d /usr/local/nginx/conf/htpasswd.users webuser1
New password:
再增加用户时取消-c选项,否则会重新创建一个新文件
htpasswd -d /usr/local/nginx/conf/htpasswd.users webuser2
New password:
2、nginx
server {
listen 80;
location /{
auth_basic "www login";
auth_basic_user_file /usr/local/nginx/conf/htpasswd.users;
}
3、apache配置
配置httpd.conf
<Directory "/www/test">
Options Indexes
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
在限制访问的目录创建.htaccess文件,内容
AuthName "www login"
AuthType basic
AuthUserFile /usr/local/apache/conf/htpasswd.users;
require valid-user
4、或者
<Directory /mnt/web1> #对/mnt/web1目录进行配置。
AuthName web1 #指定使用认证区域。
AuthType Basic
#指定使用基本身份验证。
AuthUserFile /etc/httpd/.htpassword
#指定保存用户及密码的文件。
Require valid-user
#指定文件中的所有用户均可以访问该目录。
</Directory>
<Directory /mnt/web2>
AuthName web2
AuthType
Basic
AuthUserFile
/etc/httpd/.web2
Require user google bing
jieshiyeskey #指定/etc/httpd/.web2文件中只有google、bing、jieshiyeskey可以访问该目录

分类:操作系统 | 标签: |

相关日志

评论被关闭!