02 nginx常用模块

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

第一个历程: 编写配置文件
[[email protected] 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 创建一个有密文信息的密码文件
[[email protected] 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
[[email protected] password]# curl www.oldboy.com -u oldboy
Enter host password for user ‘oldboy‘:
10.0.0.7 www.oldboy.com
[[email protected] password]# curl www.oldboy.com -u oldboy:123456
10.0.0.7 www.oldboy.com

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

时间: 2024-08-28 18:37:27

02 nginx常用模块的相关文章

Nginx 常用模块

Nginx 常用模块 1. ngx_http_autoindex_module # ngx_http_autoindex_module模块处理以斜杠字符(' / ')结尾的请求,并生成一个目录列表. # 通常,当ngx_http_index_module模块找不到索引文件时,请求被传递给ngx_http_autoindex_module模块. `# Example location / { autoindex on; } `# 启用或禁用目录列表输出. autoindex # Syntax: a

Nginx常用模块和请求处理流程简介

Nginx由内核和模块组成的,其中内核完成的工作比较简单,仅仅通过查找配置文件见客户端请求映射到一个location block,然后又这个location block中所配置的每个指令将会启动不同的模块去完成相应的工作. 一.nginx模块 (1)从结构上nginx分为核心模块,基础模块和第三方模块,例如 HTTP模块.MAIL模块.EVENT模块属于核心模块: HTTP ACCESS模块.HTTP REWRITE模块.HTTP FastCGI模块.HTTP PROXY模块属于基础模块: HT

Nginx常用模块安装命令

将目录切换至Nginx安装包目录下,使用./configure命令进行安装.一些第三方模块需要先下载过来,指定下解压后的目录即可. ./configure --prefix=/usr/local/nginx --with-http_image_filter_module --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module --with-http_gzip_s

nginx常用模块

1.nginx开启目录浏览 提供下载功能 默认情况下,网站返回index指定的主页,但如果该网站不存在主页,则将请求交给autoindex模块 如果开启autoindex模块,则提供一个下载的页面, 如果没有开启autoindex 则会报错 403 [[email protected] centos]# cat /etc/nginx/conf.d/mirror.oldxu.com.conf server { listen 80; server_name mirror.oldxu.com; cha

NGINX常用模块(二)

5.Nginx日志配置 Nginx有非常灵活的日志记录模式.每个级别的配置可以有各自独立的访问日志.日志格式 通过log_format命令定义格式 1.log_format指令 # 配置语法:包括:error.log access.log Syntax: log_format name [escape=default|json|none] string ...; Default: log_format combined "..."; Context: http # 默认Nginx定义的

HTTP扫盲及nginx基础性模块常用指令整理

第一部分:HTTP基础知识 在介绍nginx常用模块中的指令时,先来回顾一下http的相关知识: 1.http的工作原理 http的工作原理大致是这样的: a).客户端与服务器先建立一个TCP连接: b).客户端通过已建立的TCP连接向服务端发送一个http请求报文: c).服务器收到请求报文后开始解析报文.定位所请求的资源,读取资源并封装成响应报文后发送给客户端: d).如果没有启用持久连接,服务器端主动断开tcp连接,客户端被动关闭:如果启用了持久连接,那该tcp连接保持一段时间后,在该时间

nginx作为http服务器常用模块

1.详细描述常见nginx常用模块和模块的使用示例 常用模块:1.nginx核心功能模块(Core functionality)accept_mutex on|off; #Context:events这个指令的意义:当一个新连接或者说用户请求到达nginx服务时,如果accept_mutex为on,那么多个worker将以串行方式来处理,其中一个worker会被激活,其他worker继续保持休眠状态,如果accept_mutex为off,那么所有的worker将会被唤醒,但只有一个worker会

22,Nginx常用功能模块

1,Nginx常用模块(日志切割)1)我们可以在虚拟主机配置定义不同网站日志放到以自己名字命名的日志文件里2)systemctl reload nginxcd /var/log/nginx && ll 4)切割日志,让日志按照每天日期去命名5,logrotate -f /etc/logrotate.d/nginx 切割2,查看Nginx状态模块1)cd /etc/nginx/conf.d2)systemctl restart nginx3)curl www.oldzhang.comrequ

Nginx软件模块说明

Nginx软件模块说明 Nginx常用模块 注:以下只是列举Nginx常用模块,需要详细了解更多模块可以登录Nginx官方网站查看 功能模块 模块说明 ngx_http_core_module 包含一些核心的http参数配置,对应Nginx的配置为http区块部分 ngx_http_access_module 访问控制模块,用来控制网站用户对Nginx的访问 ngx_http_gzip_module 压缩模块,对返回的数据压缩,属于性能优化模块 ngx_http_proxy_module pro