[toc]

目录索引模块配置

目标索引模块

1
2
3
# 目录索引模块
ngx_http_autoindex_module模块处理以斜杠字符('/')结尾的请求,并生成目录列表。
当ngx_http_index_module模块找不到索引文件时,通常会将请求传递给ngx_http_autoindex_module模块。

image-20221213170506698

目录索引模块配置功能

1
2
3
4
5
6
7
8
9
10
# 模块配置参数

autoindex on;|off;
## 如果请求的访问站点目录下没有索引文件,将会以站点目录的形式显示在网页中
autoindex_exact_size off;|on;
## 如果开启就是显示文件大小,关闭就是显示字节大小
autoindex_localtime on;|off;
## 如果关闭就是显示格林威治时间,如果开启就是系那是本地服务器时间
autoindex_format html/xml/json/jsonp;
## 可以将网页以html/xml/json/jsonp的形式展示

基础模块

基础模块配置文件解析

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 进入配置文件
vim /etc/nginx/conf.d/xxx.conf

# 配置文件解析
server {
listen 80; # 监听 80 端口
server_name yyy.game.com; # 指定访问的域名
location / { # 配置URL
root /code/h5_games; # 站点目录
index index.html; # 指向缩影文件
autoindex on; # 指向主页面
autoindex_exact_size off; # 显示文件大小(显示单位)
autoindex_localtime on; # 修改时间为当前系统时间(不使用格林威治时间)
autoindex_format html/xml/json/jsonp; # 显示页面格式
}
}

image-20221213164748910

image-20221213164802419

状态模块

状态模块配置文件解析

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 进入配置文件
vim /etc/nginx/conf.d/xxx.conf

# 配置文件解析
server {
listen 80;
server_name yyy.game.com;

location / {
root /code/h5_games;
index index.html;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
autoindex_format html;
}
location /basic_status { # location /域名后缀 {
stub_status; # 进入状态监控模块的配置语句
}
}

image-20221213164748910

image-20221213170847936

状态模块网页内容解析

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 状态模块网页内容解析

Active connections: 2 # 当前活跃的连接数2

server
accepts # 当前的总连接数TCP
handled # 成功的TCP连接
requests # 总的http连接请求
4 4 29

Reading: 0 # 请求
Writing: 1 # 响应
Waiting: 1 # 等待的格式

## 一次TCP长连接,可以发起多次http的请求,如下参数可以修改:

vim /etc/nginx/nginx.conf
## 修改连接信息的配置文件
keepalive_timeout 65
## 65s 如果没有活动则会断开
keepalivce_timeout 0
## 关闭长链接

image-20221213170907775

访问限制模块

访问限制模块配置功能

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 允许配置语法
Syntax: allow address | CIDR | unix: | all;
## 语法结构:允许 address|CIDR|unix:|all
Default: —
## 默认值:-
Context: http, server, location, limit_except
## 配置层:http,server,location,limit_except

# 拒绝配置语法
Syntax: deny address | CIDR | unix: | all;
## 语法结构:拒绝 address|CIDR|unix:|all
Default: —
## 默认值:-
Context: http, server, location, limit_except
## 配置层:http,server,location,limit_except

# 例:
allow all; # 允许所有登录

allow 10.0.0.1; # 允许10.0.0.1登录

deny all;
allow 10.0.0.7; # 仅允许10.0.0.7登录

allow 10.0.0.0/24;
deny 10.0.0.6; # 允许10.0.0.0/24网段访问,除10.0.0.6

基于用户的访问控制模块

1
2
3
4
5
6
7
8
9
# 页面需要用户认证,使用htpasswd命令
yum install -y httpd-tools

# 创建目录
mkdir /etc/nginx/auth

# 创建一个用户名和密码
htpasswd -b -c /etc/nginx/auth/xxx_auth xxx 123
## 创建用户(xxx)和密码(123)

用户访问控制模块配置解析

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 用户访问控制模块配置解析
server {
listen 80;
server_name yyy.game.com;

location / {
root /code/h5_games;
index index.html;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
autoindex_format html;
}
location /basic_status {
stub_status;
allow all; # 允许所有人访问
auth_basic "PASSWD is 123"; # 手机访问输错密码提示
auth_basic_user_file /etc/nginx/auth/xxx_auth; # 登陆账户文件路径
}
}