Linux系统——nginx服务介绍

news/2024/5/20 16:09:16/文章来源:https://blog.csdn.net/G_D0120/article/details/136188376

目录

一、Nginx——高性能的Web服务端

1.nginx概述 

2.影响用户体验的因素

2.1客户端

2.2服务端

3.Nginx请求过程

二、Input Output 模型

1.零拷贝技术

1.1零拷贝技术的定义

1.2MMAP ( Memory Mapping )

1.3总结

2.I/O模型相关概念

3.网络I/O模型

3.1阻塞型 I/O 模型(blocking I/O)

3.2非阻塞型 I/O 模型 (nonblocking I/O )

3.3多路复用型 I/O 模型( I/O multiplexing)

3.4信号驱动式 I/O 模型(signal-driven I/O)

3.5异步 I/O 模型(asynchronous I/O)

3.6nginx驱动模型实现方式

3.6.1Select

3.6.2Poll

3.6.3Epoll

3.6.4rtsig

3.6.5kqueue

3.6.6/dev/poll

3.6.7eventport

3.6.8Iocp

3.7总结

三、Nginx概述

1.Nginx功能介绍

2.基础特性

3.Web服务相关的功能

4.Nginx进程结构

4.1主进程(master process)功能

4.2工作进程(worker process)功能

四、Nginx模块

五、安装及使用Nginx

1.编译安装Nginx

2.创建Nginx自启动文件

3.Nginx选项

4.信号

4.1分割日志——reopen

4.2指定配置 不已配置文件中的为准

5.升级/回滚Nginx

6.Nginx配置

7.全局配置

7.1关闭版本或修改版本

 7.2修改版本号内容

 7.3修改进程数

7.4绑定CPU

7.5PID路径

 7.6调整Nginx优先级

7.7调试work进程打开文件个数

7.8服务是否以后台方式运行

7.9只有master进程没有work进程

8.Event 事件

9.http设置

9.1格式 

9.2配置说明

9.3mime

9.4server下的root

9.5Server模块构建虚拟主机——重点!

9.5.1基于域名

9.5.2基于IP地址

9.5.3基于端口号

9.6alias——别名

9.7location

9.7.1location重点内容——URI匹配 

9.7.2 “ = ”——精确匹配

9.7.3 不带符号——起始于根

9.7.4“ ^~ ”——匹配开头的内容(不区分大小写)

9.7.5 “ ~ ”——包含正则表达式(区分大小写)

9.7.6“ ~* ”——包含正则表达式(不区分大小写)

9.7.7举例

www.baidu.com/

www.baidu.com/index.html

www.baidu.com/documents/document.html

www.baidu.com/images/i.gif

www.baidu.com/documents/1.jpg

9.7.8拓展

9.7.9不区分大小写举例

9.7.10优先级举例 

9.7.11Location用途

9.8Access模块——四层控制

六、小小的总结一下

1.Nginx功能介绍

2.基础特性

3.Web服务相关的功能

4.Nginx I/O模型

5.Nginx模块

5.1核心模块

5.2access模块

6.Nginx配置

7.Nginx 信号

七、调优

1.隐藏版本号——需要放在http语句模块

2.修改启动进程数

3.cpu绑定

4.调试work进程打开文件个数

5.event

6.http

7.虚拟主机

7.1基于域名

7.2基于IP地址

7.3基于端口号

8.alias——别名

9.拓展——如何让主配置文件高亮


 

一、Nginx——高性能的Web服务端

Nginx的高并发性能优于httpd服务

1.nginx概述 

Nginx是由1994年毕业于俄罗斯国立莫斯科鲍曼科技大学的同学为俄罗斯rambler.ru公司开发的,开发工作最早从2002年开始,第一次公开发布时间是2004年10月4日,版本号是0.1.02019年3月11日F5 与 NGINX达成协议,F5 将收购 NGINX 的所有已发行股票,总价值约为 6.7 亿美元。6.7亿美金约合44.97亿人民币,nginx核心模块代码长度198430(包括空格、注释),所以一行代码约为2.6万人民币

官网地址www.nginx.org(社区版);www.nginx.com(企业版)

Nginx历经十几年的迭代更新, 目前功能已经非常完善且运行稳定,另外Nginx的版本分为开发版、稳定版和过期版,nginx以功能丰富著称,它即可以作为http服务器,也可以作为反向代理服务器或者邮件服务器,能够快速的响应静态网页的请求,支持FastCGI/SSL/Virtual Host/URL Rwrite/Gzip/HTTP Basic Auth/http或者TCP的负载均衡(1.9版本以上且开启stream模块)等功能,并且支持第三方的功能扩展。天猫 淘宝 京东 小米 163 新浪等一线互联网公司都在用Nginx或者进行二次开发

基于Nginx的工作场景

  • 正向代理: 代理的客户端( 科学上网 )
  • 反向代理: 代理的服务端

2.影响用户体验的因素

2.1客户端

  • 客户端硬件配置
  • 客户端网络速率
  • 客户端与服务端距离

2.2服务端

  • 服务端网络速率
  • 服务端硬件配置
  • 服务端架构设计
  • 服务端应用程序工作模式
  • 服务端并发数量
  • 服务端响应文件大小及数量 buffer cache
  • 服务端I/O压力

3.Nginx请求过程

  1. 当用户发起 http请求需要请求一个index.html 网页文件
  2. 客户端请求与服务器端 建立连接,建立连接后, 会发送请求报文
  3. 服务端的网卡收到请求报文,会将该报文复制到 内核空间,内核空间分析报文后交给对应的程序
  4. nginx 分析该报文,将报文和自己的配置文件,进行比对,然后按照配置文件完成请求,分析后发现 客户需要 index.html
  5. 由于程序的权限问题, 没有资格直接调用磁盘上的文件,程序会再将这个请求 再次转发给内核 内核得到后请求 去磁盘上找文件,找到文件后 复制给程序
  6. 程序会构建响应报文, 构建好后在交给内核空间
  7. 内核空间得到响应报文后,再交给网卡 发给 客户

二、Input Output 模型

I/O在计算机中指Input/Output, IOPS (Input/Output Per Second)即每秒的输入输出量(或读写次数),是衡量磁盘性能的主要指标之一。IOPS是指单位时间内系统能处理的I/O请求数量,一般以每秒处理的I/O请求数量为单位,I/O请求通常为读或写数据操作请求。一次完整的I/O是用户空间的进程数据与内核空间的内核数据的报文的完整交换,但是由于内核空间与用户空间是严格隔离的,所以其数据交换过程中不能由用户空间的进程直接调用内核空间的内存数据,而是需要经历一次从内核空间中的内存数据copy到用户空间的进程内存当中,所以简单说I/O就是把数据从内核空间中的内存数据复制到用户空间中进程的内存当中。

Linux 的 I/O

磁盘I/O 磁盘I/O是进程向内核发起系统调用,请求磁盘上的某个资源比如是html 文件或者图片,然后内核通过相应的驱动程序将目标文件加载到内核的内存空间,加载完成之后把数据从内核内存再复制给进程内存,如果是比较大的数据也需要等待时间
网络I/O : 一切皆文件,本质为对socket文件的读写 网络通信就是网络协议栈到用户空间进程的IO就是网络IO

1.零拷贝技术

传统的 Linux 系统的标准 I/O 接口(read、write)是基于数据拷贝的,也就是数据都是 copy_to_user 或者 copy_from_user,这样做的好处是,通过中间缓存的机制,减少磁盘 I/O 的操作,但是坏处也很明显,大量数据的拷贝,用户态和内核态的频繁切换,会消耗大量的 CPU 资源,严重影响数据传输的性能,统计表明,在Linux协议栈中,数据包在内核态和用户态之间的拷贝所用的时间甚至占到了数据包整个处理流程时间的57.1%

1.1零拷贝技术的定义

零拷贝就是上述问题的一个解决方案,通过尽量避免拷贝操作来缓解 CPU 的压力。零拷贝并没有真正做到“0”拷贝,它更多是一种思想,很多的零拷贝技术都是基于这个思想去做的优化

1.2MMAP ( Memory Mapping )

mmap(Memory Mapping)系统调用使得进程之间通过映射同一个普通文件实现共享内存。普通文件被映射到进程地址空间后,进程可以向访问普通内存一样对文件进行访问。

mmap是一种内存映射文件的方法,即将一个文件或者其它对象映射到进程的地址空间,实现文件磁盘地址和进程虚拟地址空间中一段虚拟地址的一一对映关系。

实现这样的映射关系后,进程就可以采用指针的方式读写操作这一段内存,而系统会自动回写脏页面到对应的文件磁盘上,即完成了对文件的操作而不必再调用read,write等系统调用函数。相反,内核空间对这段区域的修改也直接反映用户空间,从而可以实现不同进程间的文件共享。内存映射减少数据在用户空间和内核空间之间的拷贝操作,适合大量数据传输

1.3总结

零拷贝技术实际上就是减少内核空间和用户空间之间的拷贝次数 零拷贝技术是减少磁盘上的I/O次数

sendfile 就是零拷贝技术

2.I/O模型相关概念

同步/异步(消息反馈机制):关注的是消息通信机制,即调用者在等待一件事情的处理结果时,被调用者是否提供完成状态的通知

同步:synchronous,被调用者并不提供事件的处理结果相关的通知消息,需要调用者主动询问事情是否处理完成
异步:asynchronous,被调用者通过状态、通知或回调机制主动通知调用者被调用者的运行状态

阻塞/非阻塞:关注调用者在等待结果返回之前所处的状态

  • 阻塞:blocking,指IO操作需要彻底完成后才返回到用户空间,调用结果返回之前,调用者被挂起,干不了别的事情。

  • 非阻塞:nonblocking,指IO操作被调用后立即返回给用户一个状态值,而无需等到IO操作彻底完成,在最终的调用结果返回之前,调用者不会被挂起,可以去做别的事情。 

  • 同步:发起者需要主动联系,执行者是否完成
  • 异步:执行者会自动反馈,是否完成
  • 阻塞:只可以做一件事,必须要等到这件事完成后才可以做其他事情
  • 非阻塞:在等待时间可以做其他事情

最好的组合是异步非阻塞;多路复用接异步非阻塞

3.网络I/O模型

阻塞型、非阻塞型、复用型、信号驱动型、异步

3.1阻塞型 I/O 模型(blocking I/O)

阻塞IO模型是最简单的I/O模型,用户线程在内核进行IO操作时被阻塞用户线程通过系统调用read发起I/O读操作,由用户空间转到内核空间。内核等到数据包到达后,然后将接收的数据拷贝到用户空间,完成read操作用户需要等待read将数据读取到buffer后,才继续处理接收的数据。整个I/O请求的过程中,用户线程是被阻塞的,这导致用户在发起IO请求时,不能做任何事情,对CPU的资源利用率不够

  • 优点:程序简单,在阻塞等待数据期间进程/线程挂起,基本不会占用 CPU 资源
  • 缺点:每个连接需要独立的进程/线程单独处理,当并发请求量大时为了维护程序,内存、线程切换开销较大,apache 的preforck使用的是这种模式

同步阻塞:程序向内核发送I/O请求后一直等待内核响应,如果内核处理请求的IO操作不能立即返回,则进程将一直等待并不再接受新的请求,并由进程轮训查看I/O是否完成,完成后进程将I/O结果返回给Client,在IO没有返回期间进程不能接受其他客户的请求,而且是有进程自己去查看I/O是否完成,这种方式简单,但是比较慢,用的比较少 

3.2非阻塞型 I/O 模型 (nonblocking I/O

查看上图可知,在设置连接为非阻塞时,当应用进程系统调用 recvfrom 没有数据返回时,内核会立即返回一个 EWOULDBLOCK 错误,而不会一直阻塞到数据准备好。如上图在第四次调用时有一个数据报准备好了,所以这时数据会被复制到 应用进程缓冲区 ,于是 recvfrom 成功返回数据当一个应用进程这样循环调用 recvfrom 时,称之为轮询 polling 。这么做往往会耗费大量CPU时间,实际使用很少  

 用户线程发起IO请求时立即返回。但并未读取到任何数据,用户线程需要不断地发起IO请求,直到数据到达后,才真正读取到数据,继续执行。即 “轮询”机制存在两个问题:如果有大量文件描述符都要等,那么就得一个一个的read。这会带来大量的Context Switch(read是系统调用,每调用一次就得在用户态和核心态切换一次)。轮询的时间不好把握。这里是要猜多久之后数据才能到。等待时间设的太长,程序响应延迟就过大;设的太短,就会造成过于频繁的重试,干耗CPU而已,是比较浪费CPU的方式,一般很少直接使用这种模型,而是在其他IO模型中使用非阻塞IO这一特性。

非阻塞:程序向内核发送请I/O求后一直等待内核响应,如果内核处理请求的IO操作不能立即返回IO结果,进程将不再等待,而且继续处理其他请求,但是仍然需要进程隔一段时间就要查看内核I/O是否完成。

3.3多路复用型 I/O 模型( I/O multiplexing)

I/O multiplexing 主要包括:select,poll,epoll三种系统调用,select/poll/epoll的好处就在于单个process就可以同时处理多个网络连接的IO。它的基本原理就是select/poll/epoll这个function会不断的轮询所负责的所有socket,当某个socket有数据到达了,就通知用户进程。当用户进程调用了select,那么整个进程会被block,而同时,kernel会“监视”所有select负责的socket,当任何一个socket中的数据准备好了,select就会返回。这个时候用户进程再调用read操作,将数据从kernel拷贝到用户进程。Apache prefork是此模式的select,work是poll模式。  

3.4信号驱动式 I/O 模型(signal-driven I/O)

信号驱动I/O的意思就是我们现在不用傻等着了,也不用去轮询。而是让内核在数据就绪时,发送信号通知我们。

调用的步骤是,通过系统调用 sigaction ,并注册一个信号处理的回调函数,该调用会立即返回,然后主程序可以继续向下执行,当有I/O操作准备就绪,即内核数据就绪时,内核会为该进程产生一个SIGIO 信号,并回调注册的信号回调函数,这样就可以在信号回调函数中系统调用 recvfrom 获取数据,将用户进程所需要的数据从内核空间拷贝到用户空间

此模型的优势在于等待数据报到达期间进程不被阻塞。用户主程序可以继续执行,只要等待来自信号处理函数的通知。

在信号驱动式 I/O 模型中,应用程序使用套接口进行信号驱动 I/O,并安装一个信号处理函数,进程继续运行并不阻塞

当数据准备好时,进程会收到一个 SIGIO 信号,可以在信号处理函数中调用 I/O 操作函数处理数据。

  • 优点:线程并没有在等待数据时被阻塞,内核直接返回调用接收信号,不影响进程继续处理其他请求因此可以提高资源的利用率
  • 缺点:信号 I/O 在大量 IO 操作时可能会因为信号队列溢出导致没法通知  

3.5异步 I/O 模型(asynchronous I/O)

异步I/O 与 信号驱动I/O最大区别在于,信号驱动是内核通知我们何时开始一个I/O操作,而异步I/O是由内核通知我们I/O操作何时完成,两者有本质区别,相当于不用去饭店场吃饭,直接点个外卖,把等待上菜的时间也给省了。所有事情都交给内核处理。

3.6nginx驱动模型实现方式

这五种 I/O 模型中,越往后,阻塞越少,理论上效率也是最优前四种属于同步 I/O,因为其中真正的I/O 操作(recvfrom)将阻塞进程/线程,只有异步 I/O 模型才与 POSIX 定义的异步 I/O 相匹配

Nginx支持在多种不同的操作系统实现不同的事件驱动模型,但是其在不同的操作系统甚至是不同的系统版本上面的实现方式不尽相同,主要有以下实现方式

3.6.1Select

select库是在linux和windows平台都基本支持的 事件驱动模型库,并且在接口的定义也基本相同,只是部分参数的含义略有差异,最大并发限制1024,是最早期的事件驱动模型。

POSIX所规定,目前几乎在所有的平台上支持,其良好跨平台支持也是它的一个优点,本质上是通过设置或者检查存放fd标志位的数据结构来进行下一步处理缺点单个进程能够监视的文件描述符的数量存在最大限制,在Linux上一般为1024,可以通过修改宏定义FD_SETSIZE,再重新编译内核实现,但是这样也会造成效率的降低单个进程可监视的fd数量被限制,默认是1024,修改此值需要重新编译内核对socket是线性扫描,即采用轮询的方法,效率较低select 采取了内存拷贝方法来实现内核将 FD 消息通知给用户空间,这样一个用来存放大量fd的数据结构,这样会使得用户空间和内核空间在传递该结构时复制开销大。

3.6.2Poll

在Linux 的基本驱动模型,windows不支持此驱动模型,是select的升级版,取消了最大的并发限制,在编译nginx的时候可以使用--with-poll_module和--without-poll_module这两个指定是否编译select库。

本质上和select没有区别,它将用户传入的数组拷贝到内核空间,然后查询每个fd对应的设备状态
其没有最大连接数的限制,原因是它是基于链表来存储的大量的fd的数组被整体复制于用户态和内核地址空间之间,而不管这样的复制是不是有意义poll特点是“水平触发”,如果报告了fd后,没有被处理,那么下次poll时会再次报告该fd select是边缘触发即只通知一次

3.6.3Epoll

epoll是库是Nginx服务器支持的最高性能的事件驱动库之一,是公认的非常优秀的事件驱动模型,它和select和poll有很大的区别,epoll是poll的升级版,但是与poll有很大的区别.
epoll的处理方式是创建一个待处理的事件列表,然后把这个列表发给内核,返回的时候在去轮训检查这个表,以判断事件是否发生,epoll支持一个进程打开的最大事件描述符的上限是系统可以打开的文件的最大数,同时epoll库的I/O效率不随描述符数目增加而线性下降,因为它只会对内核上报的“活跃”的描述符进行操作。

在Linux 2.6内核中提出的select和poll的增强版本支持水平触发LT和边缘触发ET,最大的特点在于边缘触发,它只告诉进程哪些fd刚刚变为就需态,并且只会通知一次使用“事件”的就绪通知方式,通过epoll_ctl注册fd,一旦该fd就绪,内核就会采用类似callback的回调机制来激活该fd,epoll_wait便可以收到通知
优点:没有最大并发连接的限制:能打开的FD的上限远大于1024(1G的内存能监听约10万个端口),具体查看/proc/sys/fs/file-max,此值和系统内存大小相关效率提升:非轮询的方式,不会随着FD数目的增加而效率下降;只有活跃可用的FD才会调用callback函数,即epoll最大的优点就在于它只管理“活跃”的连接,而跟连接总数无关内存拷贝,利用mmap(Memory Mapping)加速与内核空间的消息传递;即epoll使用mmap减少复制开销

3.6.4rtsig

不是一个常用事件驱动,最大队列1024,不是很常用

3.6.5kqueue

用于支持BSD系列平台的高校事件驱动模型,主要用在FreeBSD 4.1及以上版本、OpenBSD 2.0级以上版本,NetBSD级以上版本及Mac OS X 平台上,该模型也是poll库的变种,因此和epoll没有本质上的区别,都是通过避免轮训操作提供效率。

3.6.6/dev/poll

用于支持unix衍生平台的高效事件驱动模型,主要在Solaris 平台、HP/UX,该模型是sun公司在开发Solaris系列平台的时候提出的用于完成事件驱动机制的方案,它使用了虚拟的/dev/poll设备,开发人员将要见识的文件描述符加入这个设备,然后通过ioctl()调用来获取事件通知,因此运行在以上系列平台的时候请使用/dev/poll事件驱动机制。

3.6.7eventport

该方案也是sun公司在开发Solaris的时候提出的事件驱动库,只是Solaris 10以上的版本,该驱动库看防止内核崩溃等情况的发生。

3.6.8Iocp

Windows系统上的实现方式,对应第5种(异步I/O)模型。

SelectPollEpoll
操作方式遍历遍历回调
底层实现数组链表哈希表
I/O效率每次调用都进行线性遍历,时间复杂度为o(n)同左事件通知方式,每当fd就绪,系统注册的回调函数就会被调用,将就绪的fd放到rdlllist里,时间复杂度为o(1)
最大连接数

1024(x86)

2048(x64)

无上限无上限
fd拷贝每次调用select都需要把fd集合从用户拷贝到内核态每次调用poll,都需要把fd集合从用户态拷贝到内核态调用epoll_ct时拷贝进内核并保存,之后每次epoll_wait不拷贝

3.7总结

WIndows不支持Epoll;Epoll 是 poll的升级版本

Nginx 默认采用哪种连接处理类型?

A.Epoll   B.Poll   C.根据操作系统支持情况进行最优选择   D.根据操作系统支持情况随机选择

Select 会轮询遍历所有的事件集合,其次遍历的事件个数有限制;

Epoll 只会遍历已准备好的事件集合,事件个数无限制。

Linux系统默认的模型是Epoll

三、Nginx概述

1.Nginx功能介绍

  • 静态的web资源服务器html,图片,js,css,txt等静态资源
  • http/https协议的反向代理 ,7层 url
  • 结合FastCGI /uWSGI/SCGI等协议反向代理动态资源请求
  • tcp/udp协议的请求转发(反向代理) 4层

2.基础特性

  • 模块化设计,较好的扩展性
  • 高可靠性
  • 支持热部署:不停机更新配置文件,升级版本,更换日志文件
  • 低内存消耗:10000个keep-alive连接模式下的非活动连接,仅需2.5M内存
  • event-driven, aio, mmap,sendfile

3.Web服务相关的功能

  • 虚拟主机(server)
  • 支持 keep-alive 和管道连接(利用一个连接做多次请求)
  • 访问日志(支持基于日志缓冲提高其性能)
  • url rewirte
  • 路径别名
  • 基于IP及用户的访问控制
  • 支持速率限制及并发数限制
  • 重新配置和在线升级而无须中断客户的工作进程

4.Nginx进程结构

  • 多进程方式:服务器每接收到一个客户端请求就有服务器的主进程生成一个子进程响应客户端,直到用户关闭连接,这样的优势是处理速度快,子进程之间相互独立,但是如果访问过大会导致服务器资源耗尽而无法提供请求。
  • 多线程方式:与多进程方式类似,但是每收到一个客户端请求会有服务进程派生出一个线程来个客户方进行交互,一个线程的开销远远小于一个进程,因此多线程方式在很大程度减轻了web服务器对系统资源的要求,但是多线程也有自己的缺点,即当多个线程位于同一个进程内工作的时候,可以相互访问同样的内存地址空间,所以他们相互影响,一旦主进程挂掉则所有子线程都不能工作了,IIS服务器使用了多线程的方式,需要间隔一段时间就重启一次才能稳定。

4.1主进程(master process)功能

  • 对外接口:接收外部的操作(信号)
  • 对内转发:根据外部的操作的不同,通过信号管理 Worker
  • 监控:监控 worker 进程的运行状态,worker 进程异常终止后,自动重启 worker 进程
  • 读取Nginx 配置文件并验证其有效性和正确性
  • 建立、绑定和关闭socket连接
  • 按照配置生成、管理和结束工作进程
  • 接受外界指令,比如重启、升级及退出服务器等指令
  • 不中断服务,实现平滑升级,重启服务并应用新的配置
  • 开启日志文件,获取文件描述符
  • 不中断服务,实现平滑升级,升级失败进行回滚处理
  • 编译和处理perl脚本

4.2工作进程(worker process)功能

  • 所有 Worker 进程都是平等的
  • 实际处理:网络请求,由 Worker 进程处理
  • Worker进程数量:一般设置为核心数,充分利用CPU资源,同时避免进程数量过多,导致进程竞争CPU资源,
  • 增加上下文切换的损耗
  • 接受处理客户的请求
  • 将请求依次送入各个功能模块进行处理
  • I/O调用,获取响应数据
  • 与后端服务器通信,接收后端服务器的处理结果
  • 缓存数据,访问缓存索引,查询和调用缓存数据
  • 发送请求结果,响应客户的请求
  • 接收主程序指令,比如重启、升级和退出等

四、Nginx模块

  • 核心模块:是 Nginx 服务器正常运行必不可少的模块,提供错误日志记录 、配置文件解析 、事件驱动机制 、进程管理等核心功能
  • 标准HTTP模块:提供 HTTP 协议解析相关的功能,比如: 端口配置 、 网页编码设置 、 HTTP响应头设置 等等
  • 可选HTTP模块:主要用于扩展标准的 HTTP 功能,让 Nginx 能处理一些特殊的服务,比如:Flash 多媒体传输 、解析 GeoIP 请求、 网络传输压缩 、 安全协议 SSL 支持等
  • 邮件服务模块:主要用于支持 Nginx 的 邮件服务 ,包括对 POP3 协议、 IMAP 协议和 SMTP协议的支持
  • Stream服务模块: 实现反向代理功能,包括TCP协议代理 反向
  • 第三方模块:是为了扩展 Nginx 服务器应用,完成开发者自定义功能,比如: Json 支持、 Lua 支持等

nginx高度模块化,但其模块早期不支持DSO机制;1.9.11 版本支持动态装载和卸载

核心模块:core module

标准模块:

  • HTTP模块:ngx_http_*
  • HTTP Core modules   #默认功能
  • HTTP Optional modules   #需编译时指定
  • Mail 模块:ngx_mail_*
  • Stream 模块 ngx_stream_*

五、安装及使用Nginx

Nginx要使用编译安装,因为yum安装可能有些模块并不能达到我们想要的效果

yum安装的话,需要安装epel源

yum install -y epel-release
#安装epel源   额外      rpeo

yum install nginx -y

1.编译安装Nginx

  • contrib:vim 格式文件,修改nginx配置文件的格式,高亮(cp -r /opt/nginx-1.18.0/contrib/vim/* /usr/share/vim/vimfiles/)
  • conf:配置文件
  • man:man帮助 man man/nginx.8 不加路径看不了 nginx.8 文件
  • src:源码包 点c 点h 结尾的文件

统计nginx中有多少源码

https://nginx.org/en/download.html
#官网

yum -y install gcc pcre-devel openssl-devel zlib-devel openssl  openssl-devel
#安装依赖包
useradd -M -s /sbin/nologin nginx
#新建nginx用户便于管理
cd /opt/
wget http://nginx.org/download/nginx-1.18.0.tar.gz
#官网下载安装包  目前主流的还是1.18.0版本
[root@localhost opt]#ls
nginx-1.18.0.tar.gz
[root@localhost opt]#tar xf nginx-1.18.0.tar.gz 
[root@localhost opt]#ls
nginx-1.18.0  nginx-1.18.0.tar.gz
[root@localhost opt]#cd nginx-1.18.0/
[root@localhost nginx-1.18.0]#ls
auto     CHANGES.ru  configure  html     man     src
CHANGES  conf        contrib    LICENSE  README
[root@localhost nginx-1.18.0]#mkdir /apps/nginx -p
[root@localhost nginx-1.18.0]#./configure --prefix=/apps/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module
[root@localhost nginx-1.18.0]#make
[root@localhost nginx-1.18.0]#make install
[root@localhost opt]#ll /apps
总用量 0
drwxr-xr-x 6 root root 54 2月  20 15:53 nginx
[root@localhost opt]#chown -R nginx.nginx /apps/nginx
[root@localhost opt]#ll /apps
总用量 0
drwxr-xr-x 6 nginx nginx 54 2月  20 15:53 nginx
[root@localhost opt]#ln -s /apps/nginx/sbin/nginx    /usr/bin/

html网页文件;conf配置文件;contrib可以给配置文件进行高亮(有语法检查功能);man帮助;src源码包

  • conf:保存nginx所有的配置文件,其中nginx.conf是nginx服务器的最核心最主要的配置文件,其他的.conf则是用来配置nginx相关的功能的,例如fastcgi功能使用的是fastcgi.conf和fastcgi_params两个文件,配置文件一般都有个样板配置文件,是文件名.default结尾,使用的使用将其复制为并将default去掉即可。
  • html目录中保存了nginx服务器的web文件,但是可以更改为其他目录保存web文件,另外还有一个50x的web文件是默认的错误页面提示页面。
  • logs:用来保存nginx服务器的访问日志错误日志等日志,logs目录可以放在其他路径,比如/var/logs/nginx里面。
  • sbin:保存nginx二进制启动脚本,可以接受不同的参数以实现不同的功能。

 man无法直接查看nginx帮助,只能通过绝对路径进行查看

2.创建Nginx自启动文件

[root@localhost ~]#vim /usr/lib/systemd/system/nginx.service[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/apps/nginx/logs/nginx.pid
ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
LimitNOFILE=100000[Install]
WantedBy=multi-user.target[root@localhost ~]#systemctl daemon-reload
#重新加载配置
[root@localhost ~]#systemctl start nginx
[root@localhost ~]#systemctl status nginx
● nginx.service - nginx - high performance web serverLoaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)Active: active (running) since 二 2024-02-20 16:03:45 CST; 5s agoDocs: http://nginx.org/en/docs/Process: 6522 ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)Main PID: 6523 (nginx)CGroup: /system.slice/nginx.service├─6523 nginx: master process /apps/nginx/sbin/nginx -c /apps/n...└─6524 nginx: worker process2月 20 16:03:45 localhost.localdomain systemd[1]: Starting nginx - high ...
2月 20 16:03:45 localhost.localdomain systemd[1]: Started nginx - high p...
Hint: Some lines were ellipsized, use -l to show in full.

3.Nginx选项

[root@localhost ~]#nginx -h
nginx version: nginx/1.18.0
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]Options:-?,-h         : this help-v            : show version and exit-V            : show version and configure options then exit-t            : test configuration and exit-T            : test configuration, dump it and exit-q            : suppress non-error messages during configuration testing-s signal     : send signal to a master process: stop, quit, reopen, reload-p prefix     : set prefix path (default: /apps/nginx/)-c filename   : set configuration file (default: conf/nginx.conf)-g directives : set global directives out of configuration file
选项含义
-h获取帮助
-v显示版本号
-V显示模块
-t检查语法错误
-T检查所有语法并退出
-s发送信号(-s reload在不关闭软件服务的情况下重新加载配置文件)
-p指定目录
-c制定配置文件(一般配置文件在/apps/nginx/conf/nginx.conf)
-g指定开启nginx开启的进程数量(不以配置文件生效,以手写的内容为准)
[root@localhost ~]#nginx -v
#显示版本号
nginx version: nginx/1.18.0
[root@localhost ~]#nginx -V
#显示模块
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
[root@localhost ~]#nginx -t
#检查语法错误
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@localhost ~]#nginx -T
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
# configuration file /apps/nginx/conf/nginx.conf:#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;server {listen       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   html;index  index.html index.htm;}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;#    }#}# HTTPS server##server {#    listen       443 ssl;#    server_name  localhost;#    ssl_certificate      cert.pem;#    ssl_certificate_key  cert.key;#    ssl_session_cache    shared:SSL:1m;#    ssl_session_timeout  5m;#    ssl_ciphers  HIGH:!aNULL:!MD5;#    ssl_prefer_server_ciphers  on;#    location / {#        root   html;#        index  index.html index.htm;#    }#}}# configuration file /apps/nginx/conf/mime.types:types {text/html                                        html htm shtml;text/css                                         css;text/xml                                         xml;image/gif                                        gif;image/jpeg                                       jpeg jpg;application/javascript                           js;application/atom+xml                             atom;application/rss+xml                              rss;text/mathml                                      mml;text/plain                                       txt;text/vnd.sun.j2me.app-descriptor                 jad;text/vnd.wap.wml                                 wml;text/x-component                                 htc;image/png                                        png;image/svg+xml                                    svg svgz;image/tiff                                       tif tiff;image/vnd.wap.wbmp                               wbmp;image/webp                                       webp;image/x-icon                                     ico;image/x-jng                                      jng;image/x-ms-bmp                                   bmp;font/woff                                        woff;font/woff2                                       woff2;application/java-archive                         jar war ear;application/json                                 json;application/mac-binhex40                         hqx;application/msword                               doc;application/pdf                                  pdf;application/postscript                           ps eps ai;application/rtf                                  rtf;application/vnd.apple.mpegurl                    m3u8;application/vnd.google-earth.kml+xml             kml;application/vnd.google-earth.kmz                 kmz;application/vnd.ms-excel                         xls;application/vnd.ms-fontobject                    eot;application/vnd.ms-powerpoint                    ppt;application/vnd.oasis.opendocument.graphics      odg;application/vnd.oasis.opendocument.presentation  odp;application/vnd.oasis.opendocument.spreadsheet   ods;application/vnd.oasis.opendocument.text          odt;application/vnd.openxmlformats-officedocument.presentationml.presentationpptx;application/vnd.openxmlformats-officedocument.spreadsheetml.sheetxlsx;application/vnd.openxmlformats-officedocument.wordprocessingml.documentdocx;application/vnd.wap.wmlc                         wmlc;application/x-7z-compressed                      7z;application/x-cocoa                              cco;application/x-java-archive-diff                  jardiff;application/x-java-jnlp-file                     jnlp;application/x-makeself                           run;application/x-perl                               pl pm;application/x-pilot                              prc pdb;application/x-rar-compressed                     rar;application/x-redhat-package-manager             rpm;application/x-sea                                sea;application/x-shockwave-flash                    swf;application/x-stuffit                            sit;application/x-tcl                                tcl tk;application/x-x509-ca-cert                       der pem crt;application/x-xpinstall                          xpi;application/xhtml+xml                            xhtml;application/xspf+xml                             xspf;application/zip                                  zip;application/octet-stream                         bin exe dll;application/octet-stream                         deb;application/octet-stream                         dmg;application/octet-stream                         iso img;application/octet-stream                         msi msp msm;audio/midi                                       mid midi kar;audio/mpeg                                       mp3;audio/ogg                                        ogg;audio/x-m4a                                      m4a;audio/x-realaudio                                ra;video/3gpp                                       3gpp 3gp;video/mp2t                                       ts;video/mp4                                        mp4;video/mpeg                                       mpeg mpg;video/quicktime                                  mov;video/webm                                       webm;video/x-flv                                      flv;video/x-m4v                                      m4v;video/x-mng                                      mng;video/x-ms-asf                                   asx asf;video/x-ms-wmv                                   wmv;video/x-msvideo                                  avi;
}[root@localhost ~]#
[root@localhost ~]#nginx -s reload
[root@localhost ~]#vim /apps/nginx/conf/nginx.conf
[root@localhost ~]#pstree -p |grep nginx|-nginx(6523)---nginx(6620)
[root@localhost ~]#nginx -s reload
[root@localhost ~]#pstree -p |grep nginx|-nginx(6523)-+-nginx(6684)|             `-nginx(6685)

4.信号

nginx命令支持向其发送信号,实现不同功能

发送信号  nginx -s  send signal to a master process: stop, quit, reopen, reload

可以使用man手册来查看详细的信号 如果没安装,去源码包里找到man文件
man   路径/nginx.8      不加路径打不开man帮助

[root@localhost ~]#man /opt/nginx-1.18.0/man/nginx.8

内容释义
SIGINT,SIGTERM(stop)Shut down quickly(直接停止)
SIGHUP(reload)Reload configuration, start the new worker process with a new configuration, and gracefully shut down old worker processes.(重新加载配置文件)
SIGHQUIT(quit)Shut down gracefully(优雅的退出:有人在访问不会结束进程)
SIGUSR1(reopen)Reopen log files(重新分割日志)
SIGUSR2Upgrade the nginx executable on the fly. (运行中升级)
SIGWINCHShut down worker processes gracefully.(优雅的关闭worker进程,work进程负责处理请求,还有请求不会关闭)
nginx -s   stop   #立即关闭nginx
nginx -s   quit   #优雅退出   不影响业务的状态下退出
nginx -s   reload #重新加载  

4.1分割日志——reopen

[root@localhost ~]#cd /apps/nginx/
[root@localhost nginx]#ls
client_body_temp  fastcgi_temp  logs        sbin       uwsgi_temp
conf              html          proxy_temp  scgi_temp
[root@localhost nginx]#cd logs/
[root@localhost logs]#ls
access.log  error.log  nginx.pid
[root@localhost logs]#ll
总用量 8
-rw-r--r-- 1 root root    0 2月  20 16:03 access.log
-rw-r--r-- 1 root root 2921 2月  20 16:18 error.log
-rw-r--r-- 1 root root    5 2月  20 16:03 nginx.pid

目前没有任何客户端来访问,log日志还是0;如果我们要分割日志,那么要告知nginx保存日志的新位置(要先将日志备份保存)

使用其他主机来访问本机的nginx的web服务 

[root@node2 ~]#curl 192.168.241.11
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p>
</body>
</html>

此时看到日志大小有了新变化 

那么如果我们要分割日志,先将日志备份保存在本目录下

[root@localhost logs]#mv access.log access.log.bak
[root@localhost logs]#ls
access.log.bak  error.log  nginx.pid
[root@localhost logs]#ll
总用量 12
-rw-r--r-- 1 root root   91 2月  20 16:44 access.log.bak
#目前该日志文件是我们备份的文件
-rw-r--r-- 1 root root 2921 2月  20 16:18 error.log
-rw-r--r-- 1 root root    5 2月  20 16:03 nginx.pid

我们要告知nginx服务,下次保存日志的位置发生了变更

[root@localhost logs]#pstree -p |grep nginx|-nginx(6523)---nginx(10508)
[root@localhost logs]#kill -USR1 6523
#传递信号给nginx服务  告知变更存放日志位置
[root@localhost logs]#ll
总用量 12
-rw-r--r-- 1 nginx root    0 2月  20 16:47 access.log
-rw-r--r-- 1 root  root   91 2月  20 16:44 access.log.bak
-rw-r--r-- 1 nginx root 2921 2月  20 16:18 error.log
-rw-r--r-- 1 root  root    5 2月  20 16:03 nginx.pid

使用其他主机多次访问本机的nginx服务

[root@localhost logs]#ll
总用量 12
-rw-r--r-- 1 nginx root    0 2月  20 16:47 access.log
-rw-r--r-- 1 root  root   91 2月  20 16:44 access.log.bak
-rw-r--r-- 1 nginx root 2921 2月  20 16:18 error.log
-rw-r--r-- 1 root  root    5 2月  20 16:03 nginx.pid
[root@localhost logs]#ll
总用量 16
-rw-r--r-- 1 nginx root   91 2月  20 16:47 access.log
-rw-r--r-- 1 root  root   91 2月  20 16:44 access.log.bak
-rw-r--r-- 1 nginx root 2921 2月  20 16:18 error.log
-rw-r--r-- 1 root  root    5 2月  20 16:03 nginx.pid
[root@localhost logs]#ll
总用量 16
-rw-r--r-- 1 nginx root  182 2月  20 16:47 access.log
-rw-r--r-- 1 root  root   91 2月  20 16:44 access.log.bak
-rw-r--r-- 1 nginx root 2921 2月  20 16:18 error.log
-rw-r--r-- 1 root  root    5 2月  20 16:03 nginx.pid
[root@localhost logs]#ls
access.log  access.log.bak  error.log  nginx.pid

此时我们可以看到nginx已经自动更新了日志的保存位置,旧的日志也备份好了

4.2指定配置 不已配置文件中的为准

nginx -g 指定配置 不已配置文件中的为准

nginx -g 'user zhangsan;'   已张三身份运行,默认是以nginx身份
nginx -g 'daemon off;'      前台运行命令

5.升级/回滚Nginx

将nginx1.18.0升级为1.20.2版本

  1. 将旧Nginx文件换成新Nginx文件(注意备份)
  2. 向master进程发送USR2信号
  3. master进程修改pid文件名,加后缀.oldbin
  4. master进程用新Nginx文件启动新master进程,系统中将有新旧两个Nginx主进程共同提供Web服务
  5. 向旧的Nginx服务进程发送WINCH信号,使旧的Nginx worker进程平滑停止,并删除Nginx.pid.oldbin文件
  6. 向旧master进程发送QUIT信号,关闭老master
  7. 如果发现升级有问题,可以回滚向老master发送HUP,向新master发送QUIT
[root@localhost ~]#cd /opt
[root@localhost opt]#ls
nginx-1.18.0  nginx-1.18.0.tar.gz
[root@localhost ~]#wget https://nginx.org/download/nginx-1.20.2.tar.gz -P /usr/local/src

然后需要重新编译,但是不做make install操作

[root@localhost ~]#cd /usr/local/src/
[root@localhost src]#ls
nginx-1.20.2.tar.gz
[root@localhost src]#tar xf nginx-1.20.2.tar.gz 
[root@localhost src]#cd nginx-1.20.2/
[root@localhost nginx-1.20.2]#ls
auto     CHANGES.ru  configure  html     man     src
CHANGES  conf        contrib    LICENSE  README
[root@localhost nginx-1.20.2]#nginx -V
nginx version: nginx/1.18.0
#目前版本还是1.18.0的版本
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
[root@localhost nginx-1.20.2]#./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module[root@localhost nginx-1.20.2]#make[root@localhost nginx-1.20.2]#ls
auto     CHANGES.ru  configure  html     Makefile  objs    src
CHANGES  conf        contrib    LICENSE  man       README
[root@localhost nginx-1.20.2]#cd objs/
[root@localhost objs]#ls
autoconf.err  nginx    ngx_auto_config.h   ngx_modules.c  src
Makefile      nginx.8  ngx_auto_headers.h  ngx_modules.o
[root@localhost objs]#nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
[root@localhost objs]#./nginx -V
nginx version: nginx/1.20.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
[root@localhost objs]#mv /apps/nginx/sbin/nginx   /apps/nginx/sbin/nginx.bak
[root@localhost objs]#cp /usr/local/src/nginx-1.20.2/objs/nginx  /apps/nginx/sbin/
[root@localhost nginx]#cd /apps/nginx/sbin/
[root@localhost sbin]#ls
nginx  nginx.bak
[root@localhost sbin]#nginx -v
nginx version: nginx/1.20.2
[root@node2 ~]#curl 192.168.241.11 -I
HTTP/1.1 200 OK
Server: nginx/1.18.0
Date: Tue, 20 Feb 2024 10:43:26 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 20 Feb 2024 07:53:57 GMT
Connection: keep-alive
ETag: "65d45a95-264"
Accept-Ranges: bytes#目前访问还是1.18.0版本
[root@localhost sbin]#ps aux|grep -v grep|grep nginx
root      11068  0.0  0.0  46204  1160 ?        Ss   16:59   0:00 nginx: mast
nginx     11069  0.0  0.1  48736  2244 ?        S    16:59   0:00 nginx: work
[root@localhost sbin]#ls ../logs/
access.log  access.log.bak  error.log  nginx.pid
[root@localhost sbin]#cat /apps/nginx/logs/nginx.pid 
11068
[root@localhost sbin]#kill -USR2 11068
#发送信号告知nginx要更换版本了
[root@localhost sbin]#pstree -p|grep nginx
#目前新版本和旧版本都存在|-nginx(11068)-+-nginx(15556)---nginx(15557)|              `-nginx(11069)
[root@localhost sbin]#ps aux|grep -v grep|grep nginx
root      11068  0.0  0.0  46204  1348 ?        Ss   16:59   0:00 nginx: master process /apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
nginx     11069  0.0  0.1  48736  2244 ?        S    16:59   0:00 nginx: worker process
root      15556  0.0  0.1  46220  3376 ?        S    19:00   0:00 nginx: master process /apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
nginx     15557  0.0  0.1  48756  1996 ?        S    19:00   0:00 nginx: worker process
[root@localhost sbin]#cd ..
[root@localhost nginx]#ls
client_body_temp  fastcgi_temp  logs        sbin       uwsgi_temp
conf              html          proxy_temp  scgi_temp
[root@localhost nginx]#cd logs/
[root@localhost logs]#ls
access.log  access.log.bak  error.log  nginx.pid  nginx.pid.oldbin
#目前新的和旧的日志都存在
[root@localhost logs]#cat nginx.pid
15556
[root@localhost logs]#cat nginx.pid.oldbin 
11068
[root@localhost logs]#pstree -p|grep nginx|-nginx(11068)-+-nginx(15556)---nginx(15557)|              `-nginx(11069)

 新用户访问变更为1.20.2版本

[root@node2 ~]#curl 192.168.241.11 -I
HTTP/1.1 200 OK
Server: nginx/1.20.2
Date: Tue, 20 Feb 2024 11:03:06 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 20 Feb 2024 07:53:57 GMT
Connection: keep-alive
ETag: "65d45a95-264"
Accept-Ranges: bytes

让老用户优雅的退出,先模拟写入大文件

[root@localhost html]#dd if=/dev/zero of=/apps/nginx/html/m.img bs=1G count=10[root@localhost html]#ls
50x.html  index.html  m.img
[root@localhost html]#ll
总用量 8388552
-rw-r--r-- 1 nginx nginx        494 2月  20 15:53 50x.html
-rw-r--r-- 1 nginx nginx        612 2月  20 15:53 index.html
-rw-r--r-- 1 root  root  4294967296 2月  20 19:05 m.img
[root@localhost html]#ll -h
总用量 8.0G
-rw-r--r-- 1 nginx nginx  494 2月  20 15:53 50x.html
-rw-r--r-- 1 nginx nginx  612 2月  20 15:53 index.html
-rw-r--r-- 1 root  root  4.0G 2月  20 19:05 m.img

使用新机器控制在1M的速率进行下载文件 

[root@localhost nginx]#cat /apps/nginx/logs/nginx.pid.oldbin 
11068
[root@localhost nginx]#kill -WINCH `cat /apps/nginx/logs/nginx.pid.oldbin`
#等待老用户下载完成 再关闭服务

并不影响老用户继续下载 

kill -quit 进程号 优雅退出

kill 进程号 强杀

那么如何退回1.18.0版本呢

6.Nginx配置

  • 主配置文件:nginx.conf
  • 子配置文件: include conf.d/*.conf
  • 配置文件由指令和指令块构成
  • 每条指令以;分号结尾,指令与值之间以空格符号分隔
  • 指令已{}大括号将多条指令组织在一起且可以嵌套指令块
  • include语句允许组合多个配置文件以提升可维护性 
  • #号注释
  • $使用变量
  • 部分支持正则
  • 自定义变量:由用户使用set命令定义,格式: set variable_name value
  • main block:主配置段,即全局配置段,对http,mail都有效
  • event 事件驱动相关的配置   同步
  • http /https 协议相关配置段
  • mail 协议相关配置段(默认配置文件不包括)
  • stream 负载均衡 服务器相关配置段(默认配置文件不包括)

nginx服务会自动将配置文件备份好

7.全局配置

  • 核心模块:是 Nginx 服务器正常运行必不可少的模块,提供错误日志记录 、配置文件解析 、事件驱动机制 、进程管理等核心功能
  • 标准HTTP模块:提供 HTTP 协议解析相关的功能,比如: 端口配置 、 网页编码设置 、 HTTP响应头设置 等等
  • 可选HTTP模块:主要用于扩展标准的 HTTP 功能,让 Nginx 能处理一些特殊的服务,比如:Flash 多媒体传输 、解析 GeoIP 请求、 网络传输压缩 、 安全协议 SSL 支持等
  • 邮件服务模块:主要用于支持 Nginx 的 邮件服务 ,包括对 POP3 协议、 IMAP 协议和 SMTP协议的支持
  • Stream服务模块: 实现反向代理功能,包括TCP协议代理
  • 第三方模块:是为了扩展 Nginx 服务器应用,完成开发者自定义功能,比如: Json 支持、 Lua 支持等

7.1关闭版本或修改版本

[root@localhost conf]#vim /apps/nginx/conf/nginx.conf

 7.2修改版本号内容

[root@localhost ~]#cd /opt/nginx-1.18.0/src/
[root@localhost src]#ls
core  event  http  mail  misc  os  stream
[root@localhost src]#cd core/
[root@localhost core]#ls
nginx.c           ngx_inet.h             ngx_radix_tree.h
nginx.h           ngx_list.c             ngx_rbtree.c
ngx_array.c       ngx_list.h             ngx_rbtree.h
ngx_array.h       ngx_log.c              ngx_regex.c
ngx_buf.c         ngx_log.h              ngx_regex.h
ngx_buf.h         ngx_md5.c              ngx_resolver.c
ngx_conf_file.c   ngx_md5.h              ngx_resolver.h
ngx_conf_file.h   ngx_module.c           ngx_rwlock.c
ngx_config.h      ngx_module.h           ngx_rwlock.h
ngx_connection.c  ngx_murmurhash.c       ngx_sha1.c
ngx_connection.h  ngx_murmurhash.h       ngx_sha1.h
ngx_core.h        ngx_open_file_cache.c  ngx_shmtx.c
ngx_cpuinfo.c     ngx_open_file_cache.h  ngx_shmtx.h
ngx_crc32.c       ngx_output_chain.c     ngx_slab.c
ngx_crc32.h       ngx_palloc.c           ngx_slab.h
ngx_crc.h         ngx_palloc.h           ngx_spinlock.c
ngx_crypt.c       ngx_parse.c            ngx_string.c
ngx_crypt.h       ngx_parse.h            ngx_string.h
ngx_cycle.c       ngx_parse_time.c       ngx_syslog.c
ngx_cycle.h       ngx_parse_time.h       ngx_syslog.h
ngx_file.c        ngx_proxy_protocol.c   ngx_thread_pool.c
ngx_file.h        ngx_proxy_protocol.h   ngx_thread_pool.h
ngx_hash.c        ngx_queue.c            ngx_times.c
ngx_hash.h        ngx_queue.h            ngx_times.h
ngx_inet.c        ngx_radix_tree.c
[root@localhost core]#vim nginx.h

[root@localhost core]#cd ..
[root@localhost src]#vim http/ngx_http_header_filter_module.c

然后需要重新编译,要重新关闭服务

[root@localhost nginx-1.18.0]#./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
[root@localhost nginx-1.18.0]#make
[root@localhost nginx-1.18.0]#make insatall

如果再将server_tokens  开启  就会更改Server名称 

[root@localhost core]#vim /apps/nginx/conf/nginx.conf

 7.3修改进程数

[root@localhost nginx-1.18.0]#vim /apps/nginx/conf/nginx.conf

auto 就是开启进程数等于cpu真实个数 ;进程数为cpu个数

当前cpu个数为2,所以进程数为2 

psr是指psr目前进程运行在哪个cpu上 

7.4绑定CPU

将Nginx工作进程绑定到指定的CPU核心,默认Nginx是不进行进程绑定的,绑定并不是意味着当前nginx进程独占以一核心CPU,但是可以保证此进程不会运行在其他核心上,这就极大减少了nginx的工作进程在不同的cpu核心上的来回跳转,减少了CPU对进程的资源分配与回收以及内存管理等,因此可以有效的提升nginx服务器的性能。

[root@localhost nginx-1.18.0]#vim /apps/nginx/conf/nginx.conf

序号绑定cpu  cpu的亲缘性;第0号---第3号CPU

7.5PID路径

[root@localhost nginx-1.18.0]#vim /apps/nginx/conf/nginx.conf

可以指定pid路径,但是一般不建议这么做

 7.6调整Nginx优先级

优先级PRI列和NI列相加取小优先

[root@localhost nginx-1.18.0]#nginx -s reload

如果调整为-20

[root@localhost nginx-1.18.0]#vim /apps/nginx/conf/nginx.conf

7.7调试work进程打开文件个数

[root@localhost nginx-1.18.0]#vim /apps/nginx/conf/nginx.conf

[root@localhost nginx-1.18.0]#vim /etc/security/limits.conf 

7.8服务是否以后台方式运行

daemon off;

服务进程的本质是程序;一般我们所使用的服务都是后台运行,如果调用到前台是只有在容器中才会用到。

user nginx;
worker_processes 2;
worker_cpu_affinity 00000101 00000010;
daemon off;
#加入此选项

7.9只有master进程没有work进程

master_process off|on;
#是否开启Nginx的master-worker工作模式,仅用于开发调试场景,默认为on

实际运用很少

8.Event 事件

[root@localhost ~]#vim /apps/nginx/conf/nginx.conf

events {worker_connections  65536;#设置单个工作进程的最大并发连接数use epoll;#使用epoll事件驱动,Nginx支持众多的事件驱动,比如:select、poll、epoll,只能设置在events模块中设置。use  epoll可以忽略不写   因为在nginx中默认使用的是epollaccept_mutex on; #on为同一时刻一个请求轮流由work进程处理,而防止被同时唤醒所有worker,避免多个睡眠进程被唤醒的设置,默认为off,新请求会唤醒所有worker进程,此过程也称为"惊群",因此nginx刚安装完以后要进行适当的优化。建议设置为on     惊群:惊动群体(有一个客户端来访问nginx所有的worker都会来接待,其实只有一个work服务即可,如果当前默认值为off,会浪费资源)multi_accept on; #ON时Nginx服务器的每个工作进程可以同时接受多个新的网络连接,此指令默认为off,即默认为一个工作进程只能一次接受一个新的网络连接,打开后几个同时接受多个。建议设置为on#一个进程可以服务于多个客户端的访问,如果一个进程每次只接收一个客户端的访问,一对一的话,那么会浪费资源,将此配置设置为on代表一个进程可以同时接收多个客户端的访问请求
}

注意:Events中的worker_connections 设置的最大并发连接数要与worker_rilimit_nofile所有worker进程能打开文件的数量上限相匹配 

9.http设置

http是一个大的模块,其包含了多个语句块(server location等)

9.1格式 

http {......  #各server的公共配置server {    #每个server用于定义一个虚拟主机,第一个server为默认虚拟服务器...}server {     ...server_name   #虚拟主机名root     #主目录alias     #路径别名location [OPERATOR] URL {     #指定URL的特性...if CONDITION {...}}}
}

9.2配置说明

[root@localhost ~]#vim /apps/nginx/conf/nginx.conf

http {include       mime.types; #导入支持的文件类型,是相对于/apps/nginx/conf的目录default_type application/octet-stream; #除mime.types中文件类型外,设置其它文件默认类型,访问其它类型时会提示下载不匹配的类型文件#日志配置部分#log_format main '$remote_addr - $remote_user [$time_local] "$request" '#                 '$status $body_bytes_sent "$http_referer" '#                 '"$http_user_agent" "$http_x_forwarded_for"';#access_log logs/access.log main;#自定义优化参数sendfile       on; #tcp_nopush     on; #在开启了sendfile的情况下,合并请求后统一发送给客户端。#tcp_nodelay   off; #在开启了keepalived模式下的连接是否启用TCP_NODELAY选项,当为off时,延迟0.2s发送,默认On时,不延迟发送,立即发送用户响应报文。#keepalive_timeout 0;keepalive_timeout  65 65; #设置会话保持时间,第二个值为响应首部:keepAlived:timeout=65,可以和第一个值不同(第一个65是设置的会话超时等待时间,第二个是客户端可以看到的超时等到时间)#gzip on; #开启文件压缩server {listen       80; #设置监听地址和端口server_name localhost; #设置server name,可以以空格隔开写多个并支持正则表达式,如:*.kgc.com www.kgc.* ~^www\d+\.kgc\.com$ default_server    域名#charset koi8-r; #设置编码格式,默认是俄语格式,建议改为utf-8#access_log logs/host.access.log main;location /fxj  {           www.cxk.com/fsj     /apps/nginx/html   root   /data;index index.html index.htm;}#error_page 404             /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504 /50x.html; #定义错误页面location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ { #以http的方式转发php请求到指定web服务器#   proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ { #以fastcgi的方式转发php请求到php处理#   root           html;#   fastcgi_pass   127.0.0.1:9000;#   fastcgi_index index.php;#   fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;#   include       fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht { #拒绝web形式访问指定文件,如很多的网站都是通过.htaccess文件
来改变自己的重定向等功能。#   deny all;#}location ~ /passwd.html {deny all;}}# another virtual host using mix of IP-, name-, and port-based configuration##server { #自定义虚拟server#   listen       8000;#   listen       somename:8080;#   server_name somename alias another.alias;#   location / { #       root   html;#       index index.html index.htm; #指定默认网页文件,此指令由
ngx_http_index_module模块提供#   }#}# HTTPS server##server { #https服务器配置#   listen       443 ssl;#   server_name localhost;#   ssl_certificate     cert.pem;#   ssl_certificate_key cert.key;#   ssl_session_cache   shared:SSL:1m;#   ssl_session_timeout 5m;#   ssl_ciphers HIGH:!aNULL:!MD5;#   ssl_prefer_server_ciphers on;#   location / {#       root   html;#       index index.html index.htm;#   }#}

9.3mime

此项为支持的 文件格式,如果不支持的格式 会自动帮你下载,如果支持 就会显示在网页上

导入支持的文件类型,是相对于/apps/nginx/conf的目录

[root@localhost conf]#vim /apps/nginx/conf/mime.types

9.4server下的root

root指定了主页文件的位置(URL)

9.5Server模块构建虚拟主机——重点!

9.5.1基于域名
[root@localhost conf]#vim /apps/nginx/conf/nginx.conf

PC 端

[root@localhost conf]#nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: [warn] the number of "worker_processes" is not equal to the number of "worker_cpu_affinity" masks, using last mask for remaining worker processes
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@localhost nginx]#mkdir conf.d
[root@localhost nginx]#ls
client_body_temp  conf.d        html  proxy_temp  scgi_temp
conf              fastcgi_temp  logs  sbin        uwsgi_temp
[root@localhost nginx]#cat conf/nginx.conf|grep includeinclude       mime.types;include       /apps/nginx/conf.d/*.conf;#    include        fastcgi_params;
[root@localhost nginx]#cd conf.d/
[root@localhost conf.d]#ls
[root@localhost conf.d]#vim pc.conf

[root@localhost conf.d]#mkdir /opt/html
[root@localhost conf.d]#echo cxk > /opt/html/index.html
[root@localhost conf.d]#cat /opt/html/index.html 
cxk

YD 移动端

[root@localhost conf.d]#cp pc.conf yd.conf
[root@localhost conf.d]#ls
pc.conf  yd.conf
[root@localhost conf.d]#vim yd.conf 

[root@localhost conf.d]#mkdir /mnt/html
[root@localhost conf.d]#echo wyb > /mnt/html/index.html
[root@localhost conf.d]#cat /mnt/html/index.html 
wyb
[root@localhost conf.d]#nginx -s reload
[root@node2 ~]#vim /etc/hosts

[root@node2 ~]#curl www.cxk.com
cxk
[root@node2 ~]#curl www.wyb.com
wyb
9.5.2基于IP地址
[root@localhost conf.d]#vim /apps/nginx/conf.d/pc.conf

[root@localhost conf.d]#vim /opt/html/index.htmlcxk   ctrl
[root@localhost conf.d]#vim /mnt/html/index.html wyb    cxk[root@localhost conf.d]#vim yd.conf 

如果两个配置文件内容一样,那么会先读取/mnt/html/index.html;

因为在字母表中,m优先于o  所以不会再读取opt 

9.5.3基于端口号
[root@localhost conf.d]#vim /apps/nginx/conf.d/yd.conf

9.6alias——别名

[root@localhost conf.d]#vim /apps/nginx/conf/nginx.conf
server {listen 80;server_name www.kgc.com;location /cxk {root /data/nginx/html/pc/;#相当于追加  将 文件夹news追加到/data/nginx/html/pc/cxk}location /study{alias /mnt/nginx/sports/;#相当于替换 你访问 study  就是访问/mnt/nginx/sports}
}

9.7location

在一个server中location配置段可存在多个,用于实现从uri到文件系统的路径映射;ngnix会根据用户请求的URI来检查定义的所有location,按一定的优化级找出一个最佳匹配,而后应用其配置在没有使用正则表达式的时候,nginx会先在server中的多个location选取匹配度最高的一个uri,uri是用户请求的字符串,即域名后面的web文件路径,然后使用该location模块中的正则url和字符串,如果匹配成功就结束搜索,并使用此location处理此请求。

location实际是对用户的请求做个性化设置,根据用户访问的地址不同,指定访问的目录

如果没有对location做定义目录,那么会找root目录

[root@localhost conf.d]#vim pc.conf 

[root@localhost conf.d]#cd /opt
[root@localhost opt]#ls
html  nginx-1.18.0  nginx-1.18.0.tar.gz
[root@localhost opt]#echo cxk > /opt/index.html
[root@localhost opt]#nginx -s reload

location是追踪URL,找到资源所在位置

如果定义别名

[root@localhost conf.d]#vim pc.conf 
[root@localhost conf.d]#nginx -s reload
[root@localhost conf.d]#nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@localhost conf.d]#cat pc.conf 
server {listen 80;server_name www.cxk.com;root  /opt/html;location /cxk {alias /opt/;}
}

alias别名,location访问/cxk实际是访问/opt 

[root@localhost conf.d]#cd /opt/
[root@localhost opt]#ls
html  index.html  nginx-1.18.0  nginx-1.18.0.tar.gz
[root@localhost opt]#cat index.html 
cxk
[root@localhost opt]#cd html/
[root@localhost html]#ls
index.html
[root@localhost html]#cat index.html 
cxk    ctrl

如果同一目录下,有两个相同的文件,先读取第一个

9.7.1location重点内容——URI匹配 

location url 匹配的是192.168.241.11/    /后的内容

符号含义优先级
=用于标准url前,需要请求字串与uri精确匹配,大小敏感,如果匹配成功就停止向下匹配并立即处理请求1
^~用于标准url前,表示包含正则表达式,并且匹配以指定的正则表达式开头,对URI的最左边部分做匹配检查,不区分字符大小写2
~用于标准url前,表示包含正则表达式吗,并且区分大小写3
~*用于标准url前,表示包含正则表达式,并且不区分大写3
不带符号匹配起始于此uri的所有的uri4
\用于标准url前,表示包含正则表达式并且转义字符。可以将 . * ?等转义为普通符号

匹配越精确,优先级越高

9.7.2 “ = ”——精确匹配
location =/ {root  cxk;
}
#实际访问的是root根下的内容   192.168.241.11/location =/cxk {root cxk;
}
#访问的是root根下的cxk        192.168.241.11/cxk
9.7.3 不带符号——起始于根
location  {root  cxk;
}
#实际访问的是root根下的内容   192.168.241.11/
9.7.4“ ^~ ”——匹配开头的内容(不区分大小写)

~ 代表开启正则表达式

location ^~ /static/ {root  cxk;
}
#实际访问的是root根下 匹配到static或者STATIC开头的内容   192.168.241.11/static 或 192.168.241.11/STATIC
9.7.5 “ ~ ”——包含正则表达式(区分大小写)
location ~ jpg {root ckx;
}
#实际访问到的是root根下cxk/jpg的内容   192.168.241.11/cxk/jpg 或 192.168.241.11/cxk/1.jpg
9.7.6“ ~* ”——包含正则表达式(不区分大小写)
location ~* jpg {root  cxk;
}
#实际访问到的是root根下cxk/1.jpg  或 root/ckx/1.JPG  192.168.241.11/cxk/1.jpg  192.168.241.11/cxk/1.JPG
9.7.7举例
location = / {[ configuration A ]
}location / {[ configuration B ]
}location /documents/ {[ configuration C ]
}
location ^~ /images/ {[ configuration D ]
}
location ~* \.(gif|jpg|jpeg)$ {[ configuration E ]
}
www.baidu.com/

A和B均可以匹配到,但是A的优先级优于B,所以选择A

www.baidu.com/index.html

只有B可以匹配到,所以选择B

www.baidu.com/documents/document.html

只有C可以匹配到,所以选择C

www.baidu.com/images/i.gif

B、D、E均可以匹配到,但是D的优先级优于其他选项,所以选择D

www.baidu.com/documents/1.jpg

B、C、E均可以匹配到,但是E的优先级优于其他选项,所以选择E

9.7.8拓展

如下请求内容,会匹配哪个Location?

http://www.example.com/gallery/images/cat.png

A.Location /gallery {}

B.Location ~* ^/.(png|jpg)$ {}

C.Location ^~ /gallery/images {}

D.Location / {}

[root@localhost conf.d]#vim pc.conf 
[root@localhost conf.d]#cat pc.conf 
server {listen 80;server_name www.cxk.com;root /opt/html;location /index.html {root /opt/;}location = /index.html {root /mnt/;}
}
[root@localhost conf.d]#cat /mnt/index.html 
JJ
[root@localhost conf.d]#cat /opt/index.html 
cxk
[root@localhost conf.d]#nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@localhost conf.d]#nginx -s reload
[root@node2 ~]#curl 192.168.241.11/index.html
JJ
9.7.9不区分大小写举例

~* 用来对用户请求的uri做模糊匹配,uri中无论都是大写、都是小写或者大小写混合,此模式也都会匹配,通常使用此模式匹配用户request中的静态资源并继续做下一步操作,此方式使用较多注意: 此方式中,对于Linux文件系统上的文件仍然是区分大小写的,如果磁盘文件不存在,仍会提示404 ~* 虽然 不区分大小写 但是系统的文件系统区分大小写

[root@localhost conf.d]#ls
pc.conf  yd.conf
[root@localhost conf.d]#vim pc.conf 
[root@localhost conf.d]#cat pc.conf 
server {listen 80;server_name www.cxk.com;root /opt/html;location ~* /A.?\.jpg {#不区分大小写root /opt/image;}
}
[root@localhost conf.d]#mkdir /opt/image
[root@localhost conf.d]#cd /opt
[root@localhost opt]#cd image/
[root@localhost image]#ls
[root@localhost image]#rz -E
rz waiting to receive.
[root@localhost image]#ls
微信图片_20240121114511.jpg
[root@localhost image]#mv 微信图片_20240121114511.jpg A.jpg
[root@localhost image]#ls
A.jpg
[root@localhost image]#nginx -s reload

虽然软件不区分大小写,但是Linux系统还是区分大小写

9.7.10优先级举例 

location优先级:(location =) > (location ^~ 路径) > (location ~,~* 正则顺序) > 
(location 完整路径) > (location 部分起始路径) > (/)

[root@localhost image]#vim /apps/nginx/conf.d/pc.conf 
[root@localhost image]#pwd
/opt/image
[root@localhost image]#cat /apps/nginx/conf.d/pc.conf 
server {listen 80;server_name www.cxk.com;root /opt/html;
location = /1.jpg {
root /opt/image/static1;
index index.html;
}
location /1.jpg {
root /opt/image/static2;
index index.html;
}
location ~* \.(gif|jpg|jpeg|bmp|png|tiff|tif|ico|wmf|js)$ {
root /opt/image/static3;
index index.html;
}
}[root@localhost image]#nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful[root@localhost image]#mkdir static{1,2,3}
[root@localhost image]#ls
a.jpg  A.jpg  static1  static2  static3
[root@localhost image]#cd static1
[root@localhost static1]#rz -E
rz waiting to receive.
[root@localhost static1]#ls
210924150A06009-0-lp.jpg
[root@localhost static1]#mv 210924150A06009-0-lp.jpg 1.jpg
[root@localhost static1]#cd ../static2/
[root@localhost static2]#rz -E
rz waiting to receive.
[root@localhost static2]#ls
src=http___safe-img.xhscdn.com_bw1_fe3a371c-1126-46b7-ad1d-8ea3de98cb46_imageView2_2_w_1080_format_jpg&refer=http___safe-img.xhscdn.jpg
[root@localhost static2]#mv src\=http___safe-img.xhscdn.com_bw1_fe3a371c-1126-46b7-ad1d-8ea3de98cb46_imageView2_2_w_1080_format_jpg\&refer\=http___safe-img.xhscdn.jpg  1.jpg
[root@localhost static2]#cd ../static3/
[root@localhost static3]#rz -E
rz waiting to receive.
[root@localhost static3]#ls
u=2974376275,3908380467&fm=253&fmt=auto&app=138&f=GIF.jpg
[root@localhost static3]#mv u\=2974376275\,3908380467\&fm\=253\&fmt\=auto\&app\=138\&f\=GIF.jpg 1.jpg
[root@localhost static3]#cd ..
[root@localhost image]#tree
bash: tree: 未找到命令...
[root@localhost image]#nginx -s reload

[root@localhost image]#vim /apps/nginx/conf.d/pc.conf 
[root@localhost image]#cat /apps/nginx/conf.d/pc.conf 
server {listen 80;server_name www.cxk.com;root /opt/html;
location /1.jpg {
root /opt/image/static2;
index index.html;
}
location ~* \.(gif|jpg|jpeg|bmp|png|tiff|tif|ico|wmf|js)$ {
root /opt/image/static3;
index index.html;
}
}
[root@localhost image]#nginx -s reload

~ 和 ~* 

[root@localhost image]#vim /apps/nginx/conf.d/pc.conf 
[root@localhost image]#nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@localhost image]#nginx -s reload
[root@localhost image]#cat /apps/nginx/conf.d/pc.conf 
server {listen 80;server_name www.cxk.com;root /opt/html;
location ~ \.(gif|jpg|jpeg|bmp|png|tiff|tif|ico|wmf|js)$ {
root /opt/image/static1;
index index.html;
}
location ~* \.(gif|jpg|jpeg|bmp|png|tiff|tif|ico|wmf|js)$ {
root /opt/image/static3;
index index.html;
}
}

[root@localhost image]#vim /apps/nginx/conf.d/pc.conf 
[root@localhost image]#nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@localhost image]#nginx -s reload
[root@localhost image]#cat /apps/nginx/conf.d/pc.conf 
server {listen 80;server_name www.cxk.com;root /opt/html;
location ~* \.(gif|jpg|jpeg|bmp|png|tiff|tif|ico|wmf|js)$ {
root /opt/image/static1;
index index.html;
}
location ~ \.(gif|jpg|jpeg|bmp|png|tiff|tif|ico|wmf|js)$ {
root /opt/image/static3;
index index.html;
}
}

~ 和 ~*优先级一样  谁在前谁优先

9.7.11Location用途

动静分离,支持跳转

#直接匹配网站根会加速Nginx访问处理
location = /index.html {......;
}
location / {......;
}
#静态资源配置方法1
location ^~ /static/ {......;
}
#静态资源配置方法2,应用较多
location ~* \.(gif|jpg|jpeg|png|css|js|ico)$ {......;
}
#多应用配置
location ~* /app1 {......;
}
location ~* /app2 {......;
}

9.8Access模块——四层控制

四层控制:控制IP地址

[root@localhost ~]#cd /opt/nginx-1.18.0/
[root@localhost nginx-1.18.0]#ls
auto     CHANGES.ru  configure  html     Makefile  objs    src
CHANGES  conf        contrib    LICENSE  man       README
[root@localhost nginx-1.18.0]#./configure --help--help                             print this message--prefix=PATH                      set installation prefix--sbin-path=PATH                   set nginx binary pathname--modules-path=PATH                set modules path--conf-path=PATH                   set nginx.conf pathname--error-log-path=PATH              set error log pathname--pid-path=PATH                    set nginx.pid pathname--lock-path=PATH                   set nginx.lock pathname--user=USER                        set non-privileged user forworker processes--group=GROUP                      set non-privileged group forworker processes--build=NAME                       set build name--builddir=DIR                     set build directory--with-select_module               enable select module--without-select_module            disable select module--with-poll_module                 enable poll module--without-poll_module              disable poll module--with-threads                     enable thread pool support--with-file-aio                    enable file AIO support--with-http_ssl_module             enable ngx_http_ssl_module--with-http_v2_module              enable ngx_http_v2_module--with-http_realip_module          enable ngx_http_realip_module--with-http_addition_module        enable ngx_http_addition_module--with-http_xslt_module            enable ngx_http_xslt_module--with-http_xslt_module=dynamic    enable dynamic ngx_http_xslt_module--with-http_image_filter_module    enable ngx_http_image_filter_module--with-http_image_filter_module=dynamicenable dynamic ngx_http_image_filter_module--with-http_geoip_module           enable ngx_http_geoip_module--with-http_geoip_module=dynamic   enable dynamic ngx_http_geoip_module--with-http_sub_module             enable ngx_http_sub_module--with-http_dav_module             enable ngx_http_dav_module--with-http_flv_module             enable ngx_http_flv_module--with-http_mp4_module             enable ngx_http_mp4_module--with-http_gunzip_module          enable ngx_http_gunzip_module--with-http_gzip_static_module     enable ngx_http_gzip_static_module--with-http_auth_request_module    enable ngx_http_auth_request_module--with-http_random_index_module    enable ngx_http_random_index_module--with-http_secure_link_module     enable ngx_http_secure_link_module--with-http_degradation_module     enable ngx_http_degradation_module--with-http_slice_module           enable ngx_http_slice_module--with-http_stub_status_module     enable ngx_http_stub_status_module--without-http_charset_module      disable ngx_http_charset_module--without-http_gzip_module         disable ngx_http_gzip_module--without-http_ssi_module          disable ngx_http_ssi_module--without-http_userid_module       disable ngx_http_userid_module--without-http_access_module       disable ngx_http_access_module--without-http_auth_basic_module   disable ngx_http_auth_basic_module--without-http_mirror_module       disable ngx_http_mirror_module--without-http_autoindex_module    disable ngx_http_autoindex_module--without-http_geo_module          disable ngx_http_geo_module--without-http_map_module          disable ngx_http_map_module--without-http_split_clients_module disable ngx_http_split_clients_module--without-http_referer_module      disable ngx_http_referer_module--without-http_rewrite_module      disable ngx_http_rewrite_module--without-http_proxy_module        disable ngx_http_proxy_module--without-http_fastcgi_module      disable ngx_http_fastcgi_module--without-http_uwsgi_module        disable ngx_http_uwsgi_module--without-http_scgi_module         disable ngx_http_scgi_module--without-http_grpc_module         disable ngx_http_grpc_module--without-http_memcached_module    disable ngx_http_memcached_module--without-http_limit_conn_module   disable ngx_http_limit_conn_module--without-http_limit_req_module    disable ngx_http_limit_req_module--without-http_empty_gif_module    disable ngx_http_empty_gif_module--without-http_browser_module      disable ngx_http_browser_module--without-http_upstream_hash_moduledisable ngx_http_upstream_hash_module--without-http_upstream_ip_hash_moduledisable ngx_http_upstream_ip_hash_module--without-http_upstream_least_conn_moduledisable ngx_http_upstream_least_conn_module--without-http_upstream_random_moduledisable ngx_http_upstream_random_module--without-http_upstream_keepalive_moduledisable ngx_http_upstream_keepalive_module--without-http_upstream_zone_moduledisable ngx_http_upstream_zone_module--with-http_perl_module            enable ngx_http_perl_module--with-http_perl_module=dynamic    enable dynamic ngx_http_perl_module--with-perl_modules_path=PATH      set Perl modules path--with-perl=PATH                   set perl binary pathname--http-log-path=PATH               set http access log pathname--http-client-body-temp-path=PATH  set path to storehttp client request body temporary files--http-proxy-temp-path=PATH        set path to storehttp proxy temporary files--http-fastcgi-temp-path=PATH      set path to storehttp fastcgi temporary files--http-uwsgi-temp-path=PATH        set path to storehttp uwsgi temporary files--http-scgi-temp-path=PATH         set path to storehttp scgi temporary files--without-http                     disable HTTP server--without-http-cache               disable HTTP cache--with-mail                        enable POP3/IMAP4/SMTP proxy module--with-mail=dynamic                enable dynamic POP3/IMAP4/SMTP proxy module--with-mail_ssl_module             enable ngx_mail_ssl_module--without-mail_pop3_module         disable ngx_mail_pop3_module--without-mail_imap_module         disable ngx_mail_imap_module--without-mail_smtp_module         disable ngx_mail_smtp_module--with-stream                      enable TCP/UDP proxy module--with-stream=dynamic              enable dynamic TCP/UDP proxy module--with-stream_ssl_module           enable ngx_stream_ssl_module--with-stream_realip_module        enable ngx_stream_realip_module--with-stream_geoip_module         enable ngx_stream_geoip_module--with-stream_geoip_module=dynamic enable dynamic ngx_stream_geoip_module--with-stream_ssl_preread_module   enable ngx_stream_ssl_preread_module--without-stream_limit_conn_module disable ngx_stream_limit_conn_module--without-stream_access_module     disable ngx_stream_access_module--without-stream_geo_module        disable ngx_stream_geo_module--without-stream_map_module        disable ngx_stream_map_module--without-stream_split_clients_moduledisable ngx_stream_split_clients_module--without-stream_return_module     disable ngx_stream_return_module--without-stream_upstream_hash_moduledisable ngx_stream_upstream_hash_module--without-stream_upstream_least_conn_moduledisable ngx_stream_upstream_least_conn_module--without-stream_upstream_random_moduledisable ngx_stream_upstream_random_module--without-stream_upstream_zone_moduledisable ngx_stream_upstream_zone_module--with-google_perftools_module     enable ngx_google_perftools_module--with-cpp_test_module             enable ngx_cpp_test_module--add-module=PATH                  enable external module--add-dynamic-module=PATH          enable dynamic external module--with-compat                      dynamic modules compatibility--with-cc=PATH                     set C compiler pathname--with-cpp=PATH                    set C preprocessor pathname--with-cc-opt=OPTIONS              set additional C compiler options--with-ld-opt=OPTIONS              set additional linker options--with-cpu-opt=CPU                 build for the specified CPU, valid values:pentium, pentiumpro, pentium3, pentium4,athlon, opteron, sparc32, sparc64, ppc64--without-pcre                     disable PCRE library usage--with-pcre                        force PCRE library usage--with-pcre=DIR                    set path to PCRE library sources--with-pcre-opt=OPTIONS            set additional build options for PCRE--with-pcre-jit                    build PCRE with JIT compilation support--with-zlib=DIR                    set path to zlib library sources--with-zlib-opt=OPTIONS            set additional build options for zlib--with-zlib-asm=CPU                use zlib assembler sources optimizedfor the specified CPU, valid values:pentium, pentiumpro--with-libatomic                   force libatomic_ops library usage--with-libatomic=DIR               set path to libatomic_ops library sources--with-openssl=DIR                 set path to OpenSSL library sources--with-openssl-opt=OPTIONS         set additional build options for OpenSSL--with-debug                       enable debug logging

--with是需要手动安装的模块;--without是默认安装的模块

我们可以利用Access模块来实现IP访问控制

[root@localhost nginx-1.18.0]#vim /apps/nginx/conf.d/pc.conf 
[root@localhost nginx-1.18.0]#cat /apps/nginx/conf.d/pc.conf 
server {listen 80;server_name www.cxk.com;root /opt/html;location /test {root /opt/;deny 192.168.241.22;}
}
[root@localhost nginx-1.18.0]#mkdir /opt/test
[root@localhost nginx-1.18.0]#echo Genshin > /opt/test/index.html
[root@localhost nginx-1.18.0]#nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@localhost nginx-1.18.0]#nginx -s reload
[root@node2 ~]#curl 192.168.241.11/test/
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nihao/10010</center>
</body>
</html>

[root@localhost test]#vim /apps/nginx/conf.d/pc.conf 
[root@localhost test]#cat /apps/nginx/conf.d/pc.conf 
server {listen 80;server_name www.cxk.com;root /opt/html;location /test {root /opt/;deny 192.168.241.22;#拒绝192.168.241.22主机的访问allow 192.168.241.0/24;#允许192.168.241.0网段的访问deny all;#拒绝所有访问}
}#除了22主机其他该网段的主机都可以访问[root@localhost test]#nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@localhost test]#nginx -s reload

可以利用该配置在生产中配置白名单

[root@node2 ~]#curl 192.168.241.11/test/
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nihao/10010</center>
</body>
</html>

六、小小的总结一下

1.Nginx功能介绍

  • 静态的web资源服务器html,图片,js,css,txt等静态资源
  • http/https协议的反向代理 ,7层 url
  • 结合FastCGI /uWSGI/SCGI等协议反向代理动态资源请求
  • tcp/udp协议的请求转发(反向代理) 4层

2.基础特性

  • 模块化设计,较好的扩展性
  • 高可靠性
  • 支持热部署:不停机更新配置文件,升级版本,更换日志文件
  • 低内存消耗:10000个keep-alive连接模式下的非活动连接,仅需2.5M内存
  • event-driven, aio, mmap,sendfile

3.Web服务相关的功能

  • 虚拟主机(server)
  • 支持 keep-alive 和管道连接(利用一个连接做多次请求)
  • 访问日志(支持基于日志缓冲提高其性能)
  • url rewirte
  • 路径别名
  • 基于IP及用户的访问控制
  • 支持速率限制及并发数限制
  • 重新配置和在线升级而无须中断客户的工作进程

4.Nginx I/O模型

Select 会轮询遍历所有的事件集合,其次遍历的事件个数有限制;

Epoll 只会遍历已准备好的事件集合,事件个数无限制。

Linux系统默认的模型是Epoll

5.Nginx模块

5.1核心模块

[root@localhost ~]#cd /opt/nginx-1.18.0/src/core/
[root@localhost core]#ls
nginx.c           ngx_inet.h             ngx_radix_tree.h
nginx.h           ngx_list.c             ngx_rbtree.c
ngx_array.c       ngx_list.h             ngx_rbtree.h
ngx_array.h       ngx_log.c              ngx_regex.c
ngx_buf.c         ngx_log.h              ngx_regex.h
ngx_buf.h         ngx_md5.c              ngx_resolver.c
ngx_conf_file.c   ngx_md5.h              ngx_resolver.h
ngx_conf_file.h   ngx_module.c           ngx_rwlock.c
ngx_config.h      ngx_module.h           ngx_rwlock.h
ngx_connection.c  ngx_murmurhash.c       ngx_sha1.c
ngx_connection.h  ngx_murmurhash.h       ngx_sha1.h
ngx_core.h        ngx_open_file_cache.c  ngx_shmtx.c
ngx_cpuinfo.c     ngx_open_file_cache.h  ngx_shmtx.h
ngx_crc32.c       ngx_output_chain.c     ngx_slab.c
ngx_crc32.h       ngx_palloc.c           ngx_slab.h
ngx_crc.h         ngx_palloc.h           ngx_spinlock.c
ngx_crypt.c       ngx_parse.c            ngx_string.c
ngx_crypt.h       ngx_parse.h            ngx_string.h
ngx_cycle.c       ngx_parse_time.c       ngx_syslog.c
ngx_cycle.h       ngx_parse_time.h       ngx_syslog.h
ngx_file.c        ngx_proxy_protocol.c   ngx_thread_pool.c
ngx_file.h        ngx_proxy_protocol.h   ngx_thread_pool.h
ngx_hash.c        ngx_queue.c            ngx_times.c
ngx_hash.h        ngx_queue.h            ngx_times.h
ngx_inet.c        ngx_radix_tree.c

5.2access模块

[root@localhost ~]#cd /opt/nginx-1.18.0/
[root@localhost nginx-1.18.0]#./configure --help|grep access--without-http_access_module       disable ngx_http_access_module--http-log-path=PATH               set http access log pathname--without-stream_access_module     disable ngx_stream_access_module

6.Nginx配置

如果是默认(yum)安装,日志在/var/log/nginx (有access、error日志);

主要配置文件在/etc/nginx;

网页文件在/usr/share/nginx/html

[root@localhost logs]#ls /apps/nginx/logs/
access.log  access.log.bak  error.log  nginx.pid
#日志文件
[root@localhost logs]#ls /apps/nginx/
client_body_temp  conf.d        html  proxy_temp  scgi_temp
conf              fastcgi_temp  logs  sbin        uwsgi_temp
#主要文件
[root@localhost logs]#ls /apps/nginx/html/
50x.html  index.html  m.img
#网页文件

7.Nginx 信号

七、调优

1.隐藏版本号——需要放在http语句模块

server_tokens off;

2.修改启动进程数

worker_processes auto;

启动进程数按照服务器的cpu个数启动

3.cpu绑定

worker_cpu_affinity 00000001 00000010 00000100 00001000

4.调试work进程打开文件个数

worker rlimit nofile 65536;

5.event

worker_connections 65535;

设置单个工作进程的最大并发连接数

6.http

root是追加;alias是替换;location匹配URL

7.虚拟主机

7.1基于域名

[root@localhost conf]#vim /apps/nginx/conf/nginx.conf

PC 端

[root@localhost conf]#nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: [warn] the number of "worker_processes" is not equal to the number of "worker_cpu_affinity" masks, using last mask for remaining worker processes
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@localhost nginx]#mkdir conf.d
[root@localhost nginx]#ls
client_body_temp  conf.d        html  proxy_temp  scgi_temp
conf              fastcgi_temp  logs  sbin        uwsgi_temp
[root@localhost nginx]#cat conf/nginx.conf|grep includeinclude       mime.types;include       /apps/nginx/conf.d/*.conf;#    include        fastcgi_params;
[root@localhost nginx]#cd conf.d/
[root@localhost conf.d]#ls
[root@localhost conf.d]#vim pc.conf

[root@localhost conf.d]#mkdir /opt/html
[root@localhost conf.d]#echo cxk > /opt/html/index.html
[root@localhost conf.d]#cat /opt/html/index.html 
cxk

YD 移动端

[root@localhost conf.d]#cp pc.conf yd.conf
[root@localhost conf.d]#ls
pc.conf  yd.conf
[root@localhost conf.d]#vim yd.conf 

[root@localhost conf.d]#mkdir /mnt/html
[root@localhost conf.d]#echo wyb > /mnt/html/index.html
[root@localhost conf.d]#cat /mnt/html/index.html 
wyb
[root@localhost conf.d]#nginx -s reload
[root@node2 ~]#vim /etc/hosts

[root@node2 ~]#curl www.cxk.com
cxk
[root@node2 ~]#curl www.wyb.com
wyb

7.2基于IP地址

[root@localhost conf.d]#vim /apps/nginx/conf.d/pc.conf

[root@localhost conf.d]#vim /opt/html/index.htmlcxk   ctrl
[root@localhost conf.d]#vim /mnt/html/index.html wyb    cxk[root@localhost conf.d]#vim yd.conf 

如果两个配置文件内容一样,那么会先读取/mnt/html/index.html;

因为在字母表中,m优先于o  所以不会再读取opt 

7.3基于端口号

[root@localhost conf.d]#vim /apps/nginx/conf.d/yd.conf

8.alias——别名

9.拓展——如何让主配置文件高亮

 cp -r /opt/nginx-1.18.0/contrib/vim/* /usr/share/vim/vimfiles/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_982784.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Android TV遥控器探索,Android 桌面应用程序

Android TV 的遥控功能是通过红外遥控器或蓝牙遥控器来实现的。下面分别介绍这两种遥控器的工作原理&#xff1a; 红外遥控器&#xff1a; 红外遥控器是最常见的 Android TV 遥控器类型之一。 红外遥控器通过发送红外信号来控制电视或机顶盒。每个按键都有一个特定的红外编码&…

matlab滤波器设计

1、内容简介 略 51-可以交流、咨询、答疑 2、内容说明 略 3、仿真分析 略 matlab滤波器设计-butter、ellip、cheby1、cheby2_哔哩哔哩_bilibili 4、参考论文 略

神经网络系列---感知机(Neuron)

文章目录 感知机(Neuron)感知机(Neuron)的决策函数可以表示为&#xff1a;感知机(Neuron)的学习算法主要包括以下步骤&#xff1a;感知机可以实现逻辑运算中的AND、OR、NOT和异或(XOR)运算。 感知机(Neuron) 感知机(Neuron)是一种简单而有效的二分类算法&#xff0c;用于将输入…

msvcr110.dll找不到怎么修复?多种解决msvcr110.dll缺失方法分析

面对如“程序无法启动&#xff0c;因为电脑中缺失msvcr110.dll”这样的错误提示时&#xff0c;你的日常工作或游戏娱乐很可能会被迫暂停。这种问题在Windows用户中相当普遍&#xff0c;它们来源于某些共享的系统文件缺失。不过&#xff0c;好消息是解决此类错误通常并非困难任务…

Arduino中安装ESP32网络抽风无法下载 暴力解决办法 python

不知道什么仙人设计的arduino连接网络部分&#xff0c;死活下不下来。&#xff08;真的沙口&#xff0c;第一次看到这么抽风的下载口&#xff09; 操作 给爷惹火了我踏马解析json选zip直接全部下下来 把这个大家的开发板管理地址下下来跟后面python放在同一目录下&#xff0c…

IT廉连看——C语言——函数

IT廉连看——C语言——函数 一、函数是什么&#xff1f; 数学中我们常见到函数的概念。但是你了解C语言中的函数吗&#xff1f; 维基百科中对函数的定义&#xff1a;子程序 在计算机科学中&#xff0c;子程序&#xff08;英语&#xff1a;Subroutine, procedure, function, …

蛇形矩阵2

题目描述 把数1&#xff0c;2&#xff0c;3&#xff0c;4&#xff0c;5&#xff0c;…&#xff0c;按照“蛇形2”放入N*N矩阵的左三角形中&#xff0c;输出结果。 下面是N6的蛇形2的图示 输入格式 第一行1个正整数&#xff1a;N&#xff0c;范围在[1,100]。 输出格式 N行&a…

C++ 学习之函数对象

C 函数对象基本概念 在C中&#xff0c;函数对象&#xff08;Function Objects&#xff09;是一种类或结构体&#xff0c;它重载了函数调用运算符operator()&#xff0c;因此可以像函数一样被调用。函数对象有时也被称为仿函数&#xff08;Functor&#xff09;。 以下是关于C函…

ONLYOFFICE 8.0版本深度测评:革新之作还是失望之作?

引言 &#xff1a; 随着办公自动化需求的不断升级&#xff0c;拥有一款功能全面、操作便捷的办公软件显得尤为重要。在这个背景下&#xff0c;ONLYOFFICE作为一款集文档编辑、表格处理、演示制作等多功能于一体的办公套件&#xff0c;吸引了众多用户的关注。近期&#xff0c;O…

进程间通信:共享内存与信号灯集(2024/2/26)

作业1&#xff1a;共享内存 shmsnd.c: #include <myhead.h> #define PAGE_SIZE 4096int main(int argc, const char *argv[]) {//一、创建key值key_t key-1;if((keyftok("/",k))-1){perror("ftok error");return -1;}//二、根据key值创建共享内存i…

HTML+CSS+JS:花瓣登录组件

效果演示 实现了一个具有动态花朵背景和简洁登录框的登录页面效果。 Code <section><img src"./img/background.jpeg" class"background"><div class"login"><h2>Sign In</h2><div class"inputBox"…

学习磁盘管理

文章目录 一、磁盘接口类型二、磁盘设备的命名三、fdisk分区四、自动挂载五、扩容swap六、GPT分区七、逻辑卷管理八、磁盘配额九、RAID十、软硬链接 一、磁盘接口类型 IDE、SATA、SCSI、SAS、FC&#xff08;光纤通道&#xff09; IDE, 该接口是并口。SATA, 该接口是串口。SCS…

如何使用自动化工具编写测试用例?

以下为作者观点&#xff0c;仅供参考&#xff1a; 在快速变化的软件开发领域&#xff0c;保证应用程序的可靠性和质量至关重要。随着应用程序复杂性和规模的不断增加&#xff0c;仅手动测试无法满足行业需求。 这就是测试自动化发挥作用的地方&#xff0c;它使软件测试人员能…

用Python实现创建餐厅评分数据分析表

代码的功能是创建一个雷达图&#xff08;Radar Chart&#xff09;&#xff0c;也称为蜘蛛网图&#xff08;Spider Chart&#xff09;&#xff0c;用来展示不同餐厅在多个维度上的评分。雷达图是一种非常适合展示多维数据的图形&#xff0c;它能够清楚地显示每个数据点在多个变量…

抖音视频评论数据提取软件|抖音数据抓取工具

一、开发背景&#xff1a; 在业务需求中&#xff0c;我们经常需要下载抖音视频。然而&#xff0c;在网上找到的视频通常只能通过逐个复制链接的方式进行抓取和下载&#xff0c;这种操作非常耗时。我们希望能够通过关键词自动批量抓取并选择性地下载抖音视频。因此&#xff0c;为…

【JVM】线上一次fullGC排查思路

fullGC问题背景 监控告警发现&#xff0c;今天开始我们线上应用频繁出现fullGC&#xff0c;并且每次出现后磁盘都会被占满 查看监控 查看监控发现FULLGC的机器均为同一个机房的集器&#xff0c;并且该机房有线上error报错&#xff0c;数据库监控对应的时间点也有异常&#x…

将一个 PostgreSQL 数据库复制到另一个数据库中

以管理员身份进入cmd窗口&#xff0c;输入如下命令 语法&#xff1a; pg_dump -C -h 本机IP -U 本机postgresql用户名 源数据库名 | psql -h 服务器IP -U 服务器postgresql用户名 目标数据库名 示例&#xff1a; pg_dump -C -h 127.0.0.1 -U postgres test01-dbname | psql…

02|Explain详解

1. Explain工具介绍 Explain关键字可以模拟优化器执行SQL语句&#xff0c;析查询语句或结构的性能瓶颈位置使用方式&#xff1a; explain 关键字 select语句 MySQL 会在査询上设置一个标记&#xff0c;执行査询会返问执行计划的信息&#xff0c;而不是执行这条SQL。 注意:如果…

设计模式六:策略模式

1、策略模式 策略模式定义了一系列的算法&#xff0c;并将每一个算法封装起来&#xff0c;使每个算法可以相互替代&#xff0c;使算法本身和使用算法的客户端分割开来&#xff0c;相互独立。 策略模式的角色&#xff1a; 策略接口角色IStrategy&#xff1a;用来约束一系列具体…

Javaweb之SpringBootWeb案例之切入点表达式的详细解析

3.3 切入点表达式 从AOP的入门程序到现在&#xff0c;我们一直都在使用切入点表达式来描述切入点。下面我们就来详细的介绍一下切入点表达式的具体写法。 切入点表达式&#xff1a; 描述切入点方法的一种表达式 作用&#xff1a;主要用来决定项目中的哪些方法需要加入通知 …