目录
Nginx目录结构与基本运行原理
Nginx目录
# Nginx的主目录
[root@gh nginx]# ls -l
total 36
drwxr-xr-x 2 root root 4096 Apr 1 07:38 conf
drwxr-xr-x 2 root root 4096 Apr 1 07:38 html
drwxr-xr-x 2 root root 4096 Apr 1 07:46 logs
drwxr-xr-x 2 root root 4096 Apr 1 07:38 sbin
drwx------ 2 nobody root 4096 Apr 1 07:46 client_body_temp
drwx------ 2 nobody root 4096 Apr 1 07:46 fastcgi_temp
drwx------ 2 nobody root 4096 Apr 1 07:46 proxy_temp
drwx------ 2 nobody root 4096 Apr 1 07:46 scgi_temp
drwx------ 2 nobody root 4096 Apr 1 07:46 uwsgi_temp
# 其中这几个文件夹在刚安装后是没有的,主要用来存放运行过程中的临时文件
drwx------ 2 nobody root 4096 Apr 1 07:46 client_body_temp
drwx------ 2 nobody root 4096 Apr 1 07:46 fastcgi_temp
drwx------ 2 nobody root 4096 Apr 1 07:46 proxy_temp
drwx------ 2 nobody root 4096 Apr 1 07:46 scgi_temp
drwx------ 2 nobody root 4096 Apr 1 07:46 uwsgi_temp
conf
用来存放配置文件相关
html
用来存放静态文件的默认目录 html、css等
logs 日志
[root@gh logs]# pwd
/usr/local/nginx/logs
[root@gh logs]# ls -l
total 44
-rw-r--r-- 1 root root 29170 Apr 1 17:14 access.log
# access.log 用户的访问日志 时间、地点人、人物
-rw-r--r-- 1 root root 2198 Apr 1 16:11 error.log
# error_log 代表Nginx的错误日志的存放位置
-rw-r--r-- 1 root root 6 Apr 1 07:46 nginx.pid
# pid 不用关注 是Nginx运行的标识
[root@gh logs]# cat nginx.pid
18215
[root@gh logs]# ps -ef |grep nginx
root 18215 1 0 07:46 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/confnginx.conf
nobody 18216 18215 0 07:46 ? 00:00:00 nginx: worker process
root 22510 20192 0 17:20 pts/0 00:00:00 grep --color=auto nginx
sbin
nginx的主进程文件
基本运行原理
Nginx基础配置
核心配置文件
worker_processes 1;
# 默认为1,mester 启动多少个 worker_processes 进程
# worker_processes 的数值越大,Nginx并发能力越强# 以上统称为全局快
# events 快
events {
worker_connections 1024; # 单个业务进程可接受连接数
# worker_connections 的数值越大,Nginx并发能力越强
}
# http 快
# include 代表引入一个外部的文件 -> mime.types 中存放这大量的媒体类型
【# include /etc/nginx/conf.d/*.conf -> 引入了 conf.d目录下得以.conf为结尾的配置文件】
http {
include mime.types; # 引入http mime类型 【如有没有可以修改】
default_type application/octet-stream; # 如果mime类型没匹配上,默认使用二进制流的方式传输。
sendfile on; # 使用linux的 sendfile(socket, file, len) 高效网络传输,也就是数据0拷贝
keepalive_timeout 65; # 保持链接超时的时间
# server 块 虚拟主机
server {
listen 80; # listen 代表Nginx监听的端口号
server_name localhost; # localhost 代表Nginx接收请求的ip 域名、主机名
# location 快
location / {
root html; # root 将接收到的请求根据 html 去查找静态资源 相对路径/usr/local/nginx/html[自定义]
index index.html index.htm; # index 默认的去上述的路径中找到 index.html 或者 index.htm
}# 服务器端错误时 500 转向到内部的某一个地址
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html; # 未自己定义时 目录指向root 目录下的 html 找 50x.html
}
}
}
sendfile 未开启
sendfile no