14 Nginx的目录结构分析

14 Nginx的目录结构分析

14.1 目录结构

  使用 Nginx 之前,对安装好的 Nginx 目录文件进行分析,先安装工具 tree,通过 tree 方便查看 centos 系统上的文件目录结构

# 安装 tree 工具
[root@nginx-100 ~]# yum install -y tree

安装成功后,可以通过执行 tree /usr/local/nginx(tree 后面跟的是 Nginx 的安装目录),获取结果

[root@nginx-100 ~]# tree /usr/local/nginx/
/usr/local/nginx/
├── client_body_temp
├── conf
│   ├── fastcgi.conf
│   ├── fastcgi.conf.default
│   ├── fastcgi_params
│   ├── fastcgi_params.default
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types
│   ├── mime.types.default
│   ├── nginx.conf
│   ├── nginx.conf.default
│   ├── scgi_params
│   ├── scgi_params.default
│   ├── uwsgi_params
│   ├── uwsgi_params.default
│   └── win-utf
├── fastcgi_temp
├── html
│   ├── 50x.html
│   └── index.html
├── logs
│   ├── access.log
│   ├── error.log
│   └── nginx.pid
├── proxy_temp
├── sbin
│   └── nginx
├── scgi_temp
└── uwsgi_temp

9 directories, 21 files

14.2 conf

conf 配置文件分为三大类

  1.fastcgi、scgi、uwsgi:网络协议相关

  2.koi、utf:编码相关

  3.mime、nginx:配置相关

  CGI(Common Gateway Interface)通用网关【接口】,主要解决从客户端发送一个请求和数据,服务端获取到请求和数据后,可以调用 CGI【程序】处理及响应结果给客户端的一种标准规范,相对来说 CGI 处理效率较低,从而衍生了效率更高的 fastcgi、scgi、uwsgi 协议

├── conf
│   ├── fastcgi.conf: fastcgi相关配置文件
│   ├── fastcgi.conf.default:fastcgi.conf 的备份文件
│   ├── fastcgi_params:fastcgi 的参数文件
│   ├── fastcgi_params.default:fastcgi_params 的备份文件
│   ├── scgi_params:scgi 的参数文件
│   ├── scgi_params.default:scgi_params 的备份文件
│   ├── uwsgi_params:uwsgi 的参数文件
│   ├── uwsgi_params.default:uwsgi_params 的备份文件
├── conf
│   ├── koi-utf:KOI8-R(俄语主流传统编码)与 UTF-8 之间的编码映射规则
│   ├── koi-win:KOI8-R 与 CP1251(Windows-1251,Windows 系统的俄语编码)之间的编码映射规则
│   └── win-utf:CP1251(Windows-1251)与 UTF-8 之间的编码映射规则
├── conf
│   ├── mime.types:记录文本、图片等HTTP协议中Content-Type的值和文件后缀名的对应关系
│   ├── mime.types.default:mime.types 的备份文件
│   ├── nginx.conf:nginx核心配置文件
│   ├── nginx.conf.default:nginx.conf 的备份文件

14.3 html

html:页面展示的相关内容

├── html
│   ├── 50x.html:访问错误返回的页面
│   └── index.html:访问成功默认返回的页面
[root@nginx-100 ~]# cd /usr/local/nginx/html/
# 新增内容 I am junnan666
[root@nginx-100 /usr/local/nginx/html]# cat index.html 
..........
<p><em>Thank you for using nginx.</em></p>
<p><em>I am junnan666</em></p>
</body>
..........

浏览器访问:http://10.0.0.100/ ,页面中显示出在 index.html 中写入的内容 

image

14.4 logs

logs:日志相关

├── logs
│   ├── access.log:访问日志
│   ├── error.log:错误日志
│   └── nginx.pid:nginx 进程的PID

nginx.pid

# 记录 nginx 主进程id
[root@nginx-100 /usr/local/nginx]# more logs/nginx.pid 
4505
[root@nginx-100 /usr/local/nginx]# ps -ef|grep nginx
root       4505      1  0 21:03 ?        00:00:00 nginx: master process ./nginx
nobody     4506   4505  0 21:03 ?        00:00:00 nginx: worker process
root       4534   1357  0 21:13 pts/0    00:00:00 grep --color=auto nginx

access.log

# 点击页面,出现新的访问日志
[root@nginx-100 /usr/local/nginx]# tail -f logs/access.log 
10.0.0.1 - - [15/Mar/2026:21:15:39 +0800] "GET / HTTP/1.1" 304 0 \
"-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) \
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36"
10.0.0.1    客户端地址 
[15/Mar/2026:21:15:39 +0800]    请求时间
"GET / HTTP/1.1"  请求方式、请求HTTP的版本号
304   响应的状态码
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36"  客户端的相关信息描述

error.log

浏览器访问:http://10.0.0.100/abc

image

# 点击刷新,页面返回 404,同时后台出现错误日志
[root@nginx-100 /usr/local/nginx]# tail -f logs/error.log 
2026/03/15 21:23:29 [error] 4506#0: *7 open() "/usr/local/nginx/html/abc" \
failed (2: No such file or directory), client: 10.0.0.1, server: localhost, \
request: "GET /abc HTTP/1.1", host: "10.0.0.100"
2026/03/15 21:23:29   访问出错产生时间
[error]  日志级别
open() "/usr/local/nginx/html/abc" failed (2: No such file or directory)   报错信息
client: 10.0.0.1    客户端信息 
server: localhost   服务端信息
request: "GET /abc HTTP/1.1"   请求的相关内容
host: "10.0.0.100"  本机的IP

14.4 sbin

├── sbin
│   └── nginx:二进制可执行文件

nginx 用来控制 Nginx程序启动和停止的相关命令

 

———————————————————————————————————————————————————————————————————————————

                                                                                                                         无敌小马爱学习

posted on 2026-03-12 14:14  马俊南  阅读(4)  评论(0)    收藏  举报