码迷,mamicode.com
首页 > 其他好文 > 详细

02 nginx常用模块

时间:2019-10-28 13:03:59      阅读:64      评论:0      收藏:0      [点我收藏+]

标签:script   algo   tools   用户访问   erro   centos   常用   har   auth   

4. 企业中网站的安全访问配置


a 根据用户访问的地址进行控制
10.0.0.0/24 www.oldboy.com/AV/ 不能访问
172.16.1.0/24 www.oldboy.com/AV/ 可以访问

nginx访问模块: ngx_http_access_module
举例配置:
location / {
deny 192.168.1.1;
allow 192.168.1.0/24;
allow 10.1.1.0/16;
allow 2001:0db8::/32;
deny all;
}
指令用法
Syntax: deny address | CIDR | unix: | all;
Default: —
Context: http, server, location, limit_except

第一个历程: 编写配置文件
[root@web01 conf.d]# vim www.conf
server {
listen 80;
server_name www.oldboy.com;
location / {
root /html/www;
index index.html;
}
location /AV {
deny 10.0.0.0/24;
allow 172.16.1.0/24;
root /html/www;
index index.html;
}
}
补充:
location外面的信息, 全局配置信息
location里面的信息, 局部配置信息

b 根据用户访问进行认证
nginx认证模块: ngx_http_auth_basic_module
举例配置:
location / {
auth_basic "closed site"; --- 开启认证功能
auth_basic_user_file conf/htpasswd; --- 加载用户密码文件
}

第一个历程: 编写虚拟主机配置文件
server {
listen 80;
server_name www.oldboy.com;
location / {
root /html/www;
index index.html;
auth_basic "oldboy-sz-01";
auth_basic_user_file password/htpasswd;
}

第二个历程: 创建密码文件(文件中密码信息必须是密文的)
htpasswd 创建一个有密文信息的密码文件
[root@web01 conf.d]# rpm -qf `which htpasswd`
httpd-tools-2.4.6-89.el7.centos.x86_64

htpasswd命令参数说明:
-c Create a new file. *****
创建一个密码文件
-n Don‘t update file; display results on stdout.
不会更新文件; 显示文件内容信息
-b Use the password from the command line rather than prompting for it. *****
免交互方式输入用户密码信息
-i Read password from stdin without verification (for script usage).
读取密码采用标准输入方式,并不做检查 ???
-m Force MD5 encryption of the password (default).
md5的加密算法
-B Force bcrypt encryption of the password (very secure).
使用bcrypt对密码进行加密
-C Set the computing time used for the bcrypt algorithm
(higher is more secure but slower, default: 5, valid: 4 to 31).
使用bcrypt algorithm对密码进行加密
-d Force CRYPT encryption of the password (8 chars max, insecure).
密码加密方式
-s Force SHA encryption of the password (insecure).
加密方式
-p Do not encrypt the password (plaintext, insecure).
不进行加密
-D Delete the specified user.
删除指定用户
-v Verify password for the specified user.

修改密码文件权限: ???
chmod 600 ./htpasswd

500 Internal Server Error
01. 内部程序代码编写有问题
02. 程序服务中文件权限不正确

curl命令参数:
-u, --user USER[:PASSWORD] Server user and password
[root@web01 password]# curl www.oldboy.com -u oldboy
Enter host password for user ‘oldboy‘:
10.0.0.7 www.oldboy.com
[root@web01 password]# curl www.oldboy.com -u oldboy:123456
10.0.0.7 www.oldboy.com

02 nginx常用模块

标签:script   algo   tools   用户访问   erro   centos   常用   har   auth   

原文地址:https://www.cnblogs.com/linux985/p/11751169.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!