1.1

常用来提供静态服务的软件

Apache :这是中小型Web服务的主流,Web服务器中的老大哥,

Nginx :大型网站Web服务的主流,曾经Web服务器中的初生牛犊,现已长大。

Nginx 的分支 Tengine ( http://tengine.taobao.org/)目前也在飞速发展•

1.2

常用来提供动态服务的软件

  • PHP ( FastCGI ):大中小型网站都会使用,动态网页语言PHP程序的解析容器。它可配合Apache解析动态程序,不过,这里的PHP不是FastCGI守护进程横式,而是mod_php5.so ( module)也可配合Nginx解析动态程序,此时的PHP常用FastCGI守护进程模式提供服务。
  • Tomcat :中小企业动态Web服务主流,互联网Java容器主流(如jsp、do )
  • Resin :大型动态Web服务主流,互联网Java容器主流(如jsp、do )
  • IIS ( Internet information services ):微软 windows 下的 Web 服务软件(如 asp、aspx )

第2章

nginx 软件

2.1

软件介绍

2.2

NGINX 软件特性

2.2.1

HTTP服务器的特色及优点

u 

支持高并发:能支持几万并发连接(特别是静态小文件业务环境)

u 

资源消耗少:在3万并发连接下,开启10Nginx线程消耗的内存不到200MB

u 

可以做HTTP反向代理及加速缓存、即负载均衡功能,内置对RS节点服务器健康检查功能,这相当于专业的Haproxy软件或LVS的功能。

u 

具备Squid等专业缓存软件等的缓存功能。

u 

支持异步网络I/O事件横型epoll(Linux2.6+)

2.2.2

nginx功能特性

Ø 

web网站服务

Ø 

反向代理负载均衡(nginx /lvs /haproxy)

Ø 

nginx缓存服务(memcache /redis /mongodb

2.3

nginx软件的企业功能应用

<td style="width: 438pt; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: #9bbb59; border-right-color: #9bbb59; border-bottom-color: #9bbb59; border-left: none; background: #9bbb59; padding: 0cm 5.4pt;" width="584">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 1;">
    <strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: white; mso-themecolor: background1;">应用方案</span></strong>
  </p>
</td>
<td style="width: 438pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #c2d69b; border-right-width: 1pt; border-right-color: #c2d69b; background: #eaf1dd; padding: 0cm 5.4pt;" width="584">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">若是高并发场景,尽量采用</span><span lang="EN-US">Nginx</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">或</span><span lang="EN-US">Lighttpd</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">,二者首选</span><span lang="EN-US">Nginx</span>
  </p>
</td>
<td style="width: 438pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #c2d69b; border-right-width: 1pt; border-right-color: #c2d69b; padding: 0cm 5.4pt;" width="584">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">理论上采用</span><span lang="EN-US">Nginx</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">和</span><span lang="EN-US">Apache</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">均可,建议选择</span><span lang="EN-US">Nginx</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">,为了避免相同业务的服务软件多样化,增加额外维护成本。动态业务可以由</span><span lang="EN-US">Nginx</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">兼做前端代理,再根据页面元素的类型或目录,转发到后端相应的服务器处理进程。</span>
  </p>
  
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="background: lime; mso-highlight: lime;" lang="EN-US">---</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; background: lime; mso-highlight: lime;">首选</span><span style="background: lime; mso-highlight: lime;" lang="EN-US">tomcat</span>
  </p>
</td>
<td style="width: 438pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #c2d69b; border-right-width: 1pt; border-right-color: #c2d69b; background: #eaf1dd; padding: 0cm 5.4pt;" width="584">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; text-indent: 24.0pt; mso-char-indent-count: 2.0; mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">采用</span><span lang="EN-US">Nginx</span>
  </p>
  
  <p class="MsoNormal" style="text-indent: 21.0pt; mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">利用</span><span lang="EN-US">nginx</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">软件是无法处理动态业务请求,要让</span><span lang="EN-US">nginx</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">结合</span><span lang="EN-US">php</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">软件处理动态业务请求,在加上</span><span lang="EN-US">mysql </span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">即</span> <strong><span lang="EN-US">LNMP</span></strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">架构</span>
  </p>
</td>

2.4

nginx软件的动态访问瓶颈

2.4.1

与其他软件的对比

² 

Apache2.2版本非常稳定强大,据官方说,Apache2.4版本性能更强。

² 

Prefork模式取消了进程创建开销,性能很高。

² 

处理动态业务数据时,因关联到后端的引擎和数据库,瓶颈不在Apache上。

² 

高并发时消耗系统资源相对多一些。

² 

基于传统的select模型,高并发能力有限。

² 

支持扩展库,可通过DSOapxs方法编译安装额外的插件功能,不需要重新编译Apache

² 

功能多,更稳定,更安全,插件也多。

² 

市场份额在逐年递减

n 

基于异步网结I/O 型(epollk kqueue

n 

具备支持高性能,高并发的特性,并发连接可达数万。

n 

对小文件(小于1 MB的静态文件)高并发支持很好,性能很高

n 

不支持类似 ApacheDSO模式、扩展库必须编译进主程序(缺点)

n 

进程占用系统资源比较低。

n 

支持Web、反向ProxyCache三大重点功能,幷且都很优秀。

n 

市场份额在逐年快速增加。

² 

基于异步网络 I/ O模型,性能、并发都与 Nginx相近。

² 

扩展库是 SO模式,比Nginx灵活

² 

目前国内的使用率比较低,安全性没有 ApacheNginx好。

² 

通过插件(mod_secdownload)可实现文件 URL地址加密(优点)

² 

社区不活跃,市场份额较低,

2.4.2

最主要的区别select & epoll

NGINX 使用的是epoll 和Kqueue 异步网络I/O模型,而apache使用的是传统的select模型

2.4.3

apache selectnginx epoll技术对比图

<td style="width: 219.7pt; border-top-width: 1pt; border-top-color: #4bacc6; border-left: none; border-bottom-width: 1pt; border-bottom-color: #4bacc6; border-right: none; background: #4bacc6; padding: 0cm 5.4pt;" valign="top" width="293">
  <p class="MsoNormal">
    <strong><span style="color: white; mso-themecolor: background1;" lang="EN-US">select</span></strong>
  </p>
</td>

<td style="width: 204.1pt; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: #4bacc6; border-right-color: #4bacc6; border-bottom-color: #4bacc6; border-left: none; background: #4bacc6; padding: 0cm 5.4pt;" valign="top" width="272">
  <p class="MsoNormal">
    <strong><span style="color: white; mso-themecolor: background1;" lang="EN-US">epoll</span></strong>
  </p>
</td>
<td style="width: 219.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #92cddc; border-right-width: 1pt; border-right-color: #92cddc; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="293">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">随着连接数的增加性能急剧下降。处理成千上万的并发连接数,性能很差</span>
  </p>
</td>

<td style="width: 204.1pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #92cddc; border-right-width: 1pt; border-right-color: #92cddc; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="272">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">随着连接数的增加,性能基本上没有下降。处理成千上万连接时性能很好</span>
  </p>
</td>
<td style="width: 219.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #92cddc; border-right-width: 1pt; border-right-color: #92cddc; padding: 0cm 5.4pt;" valign="top" width="293">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">连接数有限制,处理的最大连接数不超过</span><span lang="EN-US">1024</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">,如果要处理的连接数超过</span><span lang="EN-US">1024</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">个,则需要修改</span><span lang="EN-US">FD_SETSIZE</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">宏,并重新编译</span>
  </p>
</td>

<td style="width: 204.1pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #92cddc; border-right-width: 1pt; border-right-color: #92cddc; padding: 0cm 5.4pt;" valign="top" width="272">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">连接数无限制</span>
  </p>
</td>
<td style="width: 219.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #92cddc; border-right-width: 1pt; border-right-color: #92cddc; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="293">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">线性轮询</span>
  </p>
</td>

<td style="width: 204.1pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #92cddc; border-right-width: 1pt; border-right-color: #92cddc; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="272">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">回调</span><span lang="EN-US">callback</span>
  </p>
</td>
<td style="width: 219.7pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #92cddc; border-right-width: 1pt; border-right-color: #92cddc; padding: 0cm 5.4pt;" valign="top" width="293">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">低</span>
  </p>
</td>

<td style="width: 204.1pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #92cddc; border-right-width: 1pt; border-right-color: #92cddc; padding: 0cm 5.4pt;" valign="top" width="272">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">中</span>
  </p>
</td>

第3章

nginx的安装与使用

3.1

nginx软件的编译安装步骤

3.1.1

检查软件安装的系统环境

3.1.2

安装nginx的依赖包(pcre-devel openssl-devel

3.1.3

下载nginx软件

3.1.4

创建管理用户 www

3.1.5

 nginx软件编译安装过程

3.1.5.1 

注意

3.1.5.2 

编译安装软件

3.1.6

创建软连接

3.1.7

精简化nginx.conf 主配置文件内容

3.1.8

启动程序

3.1

nginx 目录结构

3.2

nginx.conf 配置文件说明

3.2.1

站点目录与首页文件概 

3.2.2

配置文件详解 

3.3

【常见错误】nginx软件的编译安装常见错误说明

3.3.1

nginx软件安装过程中遇到的问题

3.3.2

nginx软件启动过程中遇到的问题

3.3.3

启动 Nginx 时如下报错“nginx:[emerg]getpwnam(nginx”〉failed”

3.3.4

编译安装pcre编译软件时,gcc不全导致报错(本文使用yum安装不存在此问题)

3.3.5

nginx软件编译安装后,看不到程序目录(/application

3.3.6

nginx软件排查问题三部曲说明

3.3.7

【注意】403状态码出现情况原因

3.4

nginx软件使用命令参数

3.4.1

nginx 启动方法

3.4.2

nginx 停止方法

3.4.3

nginx 重启方法 (平滑重启)

3.4.4

检查配置文件语法是否正确

3.4.5

显示配置参数  -V (大写V

3.4.6

nginx软件使用过程中深入说明

3.5

nginx软件静态页面编写过程

<meta charset="utf-8">

"http://blog.znix.top"> <img src="znix.png" /> </a>

第4章

nginx进阶虚拟主机配置

4.1

企业要求】需要按照以前nginx服务编译安装过程安装

4.1.1

语法检查】检查配置文件

4.2

首页文件不存在利用nginx服务搭建文件共享服务器

4.2.1

进行curl时,报403错误,因为没有首页文件信息

4.2.2

autoindex on参数实践

4.3

【概念】虚拟主机的概念和类型

4.3.1

虚拟主机概念

4.3.2

虚拟主机类型

4.3.3

Nginx配置虚拟主机的步骤如下(适合各类虚拟主机类型)

4.4

【实践】虚拟主机配置

4.4.1

基于域名的虚拟主机

4.4.2

基于端口的虚拟主机

4.4.3

基于IP的虚拟主机

4.5

【规范化配置】nginx配置文件企业规范化

4.5.1

第一个里程碑:  创建虚拟主机配置文件存储目录

4.5.2

第二个里程碑: 生产虚拟主机配置文件

4.5.3

第三个里程碑: 修改nginx配置文件使之加载识别虚拟主机配置文件

4.5.4

重启服务

4.5.5

检查监听端口

4.5.6

查看配置文件的加载顺序

4.5.7

【优化】调整 inculde的加载顺序,指定第一个加载为conf

4.5.8

重启服务

4.5.9

说明;

4.6

别名的配置

4.7

status 状态模块

4.7.1

状态模块的配置

4.7.2

状态模块说明

<td style="width: 352.95pt; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: #4bacc6; border-right-color: #4bacc6; border-bottom-color: #4bacc6; border-left: none; background: #4bacc6; padding: 0cm 5.4pt;" valign="top" width="471">
  <p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 1;" align="center">
    <strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: white; mso-themecolor: background1;">参数说明</span></strong>
  </p>
</td>
<td style="width: 352.95pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #92cddc; border-right-width: 1pt; border-right-color: #92cddc; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="471">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">当前的活动客户端连接数量</span>
  </p>
</td>
<td style="width: 352.95pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #92cddc; border-right-width: 1pt; border-right-color: #92cddc; padding: 0cm 5.4pt;" valign="top" width="471">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">接受客户端连接的总数</span>
  </p>
</td>
<td style="width: 352.95pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #92cddc; border-right-width: 1pt; border-right-color: #92cddc; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="471">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">处理的连接总数</span>
  </p>
</td>
<td style="width: 352.95pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #92cddc; border-right-width: 1pt; border-right-color: #92cddc; padding: 0cm 5.4pt;" valign="top" width="471">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">客户端请求的总数</span>
  </p>
</td>
<td style="width: 352.95pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #92cddc; border-right-width: 1pt; border-right-color: #92cddc; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="471">
  <p class="MsoNormal">
    <span lang="EN-US">nginx</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">正在读请求头的当前连接数。</span>
  </p>
</td>
<td style="width: 352.95pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #92cddc; border-right-width: 1pt; border-right-color: #92cddc; padding: 0cm 5.4pt;" valign="top" width="471">
  <p class="MsoNormal">
    <span lang="EN-US">nginx</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">正在将响应写回客户端的当前连接数。</span>
  </p>
</td>
<td style="width: 352.95pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: #92cddc; border-right-width: 1pt; border-right-color: #92cddc; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="471">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">当前空闲客户端连接数等待一个请求。</span>
  </p>
</td>

4.8

nginx的日志功能

4.8.1

定义错误日志信息

4.8.2

访问日志配置

#access_log logs/access.log main;

      server{
      listen  </span>80<span style="color: #000000;">;
      server_name  status.nmtui.com;
      location </span>/<span style="color: #000000;"> {
        stub_status on;
        access_log   off;
      }
    }
include extra</span>/<span style="color: #000000;">www.conf;
include extra</span>/<span style="color: #000000;">bbs.conf;
include extra</span>/<span style="color: #000000;">blog.conf;

}

4.8.3

【重要】访问日志信息说明

<td style="width: 226.35pt; border-top-width: 1pt; border-top-color: white; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right: none; background: #4bacc6; padding: 0cm 5.4pt;" valign="top" width="302">
  <p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 1;" align="center">
    <strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: white; mso-themecolor: background1;">日志内容</span></strong>
  </p>
</td>

<td style="width: 134.4pt; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: white; border-right-color: white; border-bottom-color: white; border-left: none; background: #4bacc6; padding: 0cm 5.4pt;" valign="top" width="179">
  <p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 1;" align="center">
    <strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: white; mso-themecolor: background1;">含义</span></strong>
  </p>
</td>
<td style="width: 226.35pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #b6dde8; padding: 0cm 5.4pt;" valign="top" width="302">
  <p class="MsoNormal">
    <span lang="EN-US">10.0.0.1</span>
  </p>
</td>

<td style="width: 134.4pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #b6dde8; padding: 0cm 5.4pt;" valign="top" width="179">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">客户端</span><span lang="EN-US">ip</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">地址</span>
  </p>
</td>
<td style="width: 226.35pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="302">
  <p class="MsoNormal">
    <span lang="EN-US">-</span>
  </p>
</td>

<td style="width: 134.4pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="179">
  <p class="MsoNormal">
    <span lang="EN-US"> </span>
  </p>
</td>
<td style="width: 226.35pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #b6dde8; padding: 0cm 5.4pt;" valign="top" width="302">
  <p class="MsoNormal">
    <span lang="EN-US">-</span>
  </p>
</td>

<td style="width: 134.4pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #b6dde8; padding: 0cm 5.4pt;" valign="top" width="179">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">显示远程访问者用户信息</span>
  </p>
</td>
<td style="width: 226.35pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="302">
  <p class="MsoNormal">
    <span lang="EN-US">[22/Oct/2017:16:04:54 +0800]</span>
  </p>
</td>

<td style="width: 134.4pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="179">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">显示访问时间</span>
  </p>
</td>
<td style="width: 226.35pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #b6dde8; padding: 0cm 5.4pt;" valign="top" width="302">
  <p class="MsoNormal">
    <span lang="EN-US">GET / HTTP/1.1"</span>
  </p>
</td>

<td style="width: 134.4pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #b6dde8; padding: 0cm 5.4pt;" valign="top" width="179">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">请求行信息</span>
  </p>
</td>
<td style="width: 226.35pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="302">
  <p class="MsoNormal">
    <span lang="EN-US">304</span>
  </p>
</td>

<td style="width: 134.4pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="179">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">状态码</span>
  </p>
</td>
<td style="width: 226.35pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #b6dde8; padding: 0cm 5.4pt;" valign="top" width="302">
  <p class="MsoNormal">
    <span lang="EN-US"></span>
  </p>
</td>

<td style="width: 134.4pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #b6dde8; padding: 0cm 5.4pt;" valign="top" width="179">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">响应报文主体内容大小</span>
  </p>
</td>
<td style="width: 226.35pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="302">
  <p class="MsoNormal">
    <span lang="EN-US">-</span>
  </p>
</td>

<td style="width: 134.4pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="179">
  <p class="MsoNormal">
    <span lang="EN-US"> </span>
  </p>
</td>
<td style="width: 226.35pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #b6dde8; padding: 0cm 5.4pt;" valign="top" width="302">
  <p class="MsoNormal">
    <span lang="EN-US">Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36</span>
  </p>
</td>

<td style="width: 134.4pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #b6dde8; padding: 0cm 5.4pt;" valign="top" width="179">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">客户端浏览网页工具信息</span>
  </p>
</td>
<td style="width: 226.35pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="302">
  <p class="MsoNormal">
    <span lang="EN-US">-</span>
  </p>
</td>

<td style="width: 134.4pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: white; border-right-width: 1pt; border-right-color: white; background: #daeef3; padding: 0cm 5.4pt;" valign="top" width="179">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">反向代理转发</span>
  </p>
</td>
<td style="width: 360pt; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left: none; background: #a6a6a6; padding: 0cm 5.4pt;" width="480">
  <p class="MsoNormal" style="text-align: center;" align="center">
    <strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">说明</span></strong>
  </p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">记录访问网站的客户端地址;即源</span><span lang="EN-US">IP</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">地址</span>
  </p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">当前端有代理服务器时,设置</span><span lang="EN-US">web</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">节点记录客户端地址的配置,此参数生效的</span>
  </p>
  
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">前提是代理服务器上也进行了相关的</span><span lang="EN-US">x_forwarded_for</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">设置</span>
  </p>
  
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">可以记录用户真实的</span><span lang="EN-US">IP</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">地址信息</span>
  </p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">远程客户端用户名称</span>
  </p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">记录访问时间与时区</span>
  </p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">用户的</span><span lang="EN-US">http</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">请求起始行信息</span>
  </p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span lang="EN-US">http</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">状态码,记录请求返回的状态,例如:</span><span lang="EN-US">200 , 404 , 301</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">等</span>
  </p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">服务器发送给客户端的响应</span><span lang="EN-US">body</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">字节数</span>
  </p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">记录此次请求是从哪个链接访问过来的,可以根据</span><span lang="EN-US">referer</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">进行防盗链设置</span>
  </p>
  
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">即表示是哪个网站介绍过来的</span>
  </p>
</td>
<td style="width: 360pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="480">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">记录客户端访问信息,例如:浏览器、手机客户端等</span>
  </p>
</td>

4.8.4

日志的切割

4.9

企业需求解决(location应用)

4.9.1

需求处理 –location的应用

4.9.2

location 语法

  <td style="width: 21.88%; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left: none; background: #a6a6a6; padding: 0cm 5.4pt; height: 27.5pt;" width="21%">
    <p class="MsoNormal" style="text-align: center;" align="center">
      <strong><span lang="EN-US">[=|~|~*|^~]</span></strong>
    </p>
  </td>
  
  <td style="width: 23.02%; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left: none; background: #a6a6a6; padding: 0cm 5.4pt; height: 27.5pt;" width="23%">
    <p class="MsoNormal" style="text-align: center;" align="center">
      <strong><span lang="EN-US">uri</span></strong>
    </p>
  </td>
  
  <td style="width: 38.48%; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left: none; background: #a6a6a6; padding: 0cm 5.4pt; height: 27.5pt;" width="38%">
    <p class="MsoNormal" style="text-align: center;" align="center">
      <strong><span lang="EN-US">{....}</span></strong>
    </p>
  </td>
</tr>

<tr>
  <td style="width: 16.62%; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-top: none; padding: 0cm 5.4pt;" valign="top" width="16%">
    <p class="MsoNormal" style="text-align: center;" align="center">
      <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">指令</span>
    </p>
  </td>
  
  <td style="width: 21.88%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" valign="top" width="21%">
    <p class="MsoNormal" style="text-align: center;" align="center">
      <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">匹配标识</span>
    </p>
  </td>
  
  <td style="width: 23.02%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" valign="top" width="23%">
    <p class="MsoNormal" style="text-align: center;" align="center">
      <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">匹配的网站地址</span>
    </p>
  </td>
  
  <td style="width: 38.48%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" valign="top" width="38%">
    <p class="MsoNormal" style="text-align: center;" align="center">
      <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">匹配</span><span lang="EN-US">URI</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">后要执行的配置段</span>
    </p>
  </td>
</tr>

u 

匹配内容区分大小写

u 

~* 匹配内容不区分的小写

u 

!~ 取反

u 

^~ 但多个匹配同时存在,优先匹配 ^~匹配的内容;不做正则表达式的检查 (优先处理)

4.9.3

官方配置示例

location / { [ configuration B ] }

location /documents/ { [ configuration C ] }

location ^~ /images/ { [ configuration D ] }

location ~* .(gif|jpg|jpeg)$ { [ configuration E ] }

<td style="width: 241pt; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left: none; background: #a6a6a6; padding: 0cm 5.4pt;" width="321">
  <p class="MsoNormal" style="text-align: center;" align="center">
    <strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">不用</span><span lang="EN-US">URI</span></strong><strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">及特殊字符组合匹配</span></strong>
  </p>
</td>

<td style="width: 246.6pt; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left: none; background: #a6a6a6; padding: 0cm 5.4pt;" width="329">
  <p class="MsoNormal" style="text-align: center;" align="center">
    <strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">匹配说明</span></strong>
  </p>
</td>
<td style="width: 241pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="321">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span lang="EN-US">location = / {}</span>
  </p>
</td>

<td style="width: 246.6pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="329">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">精确匹配</span><span lang="EN-US"> /</span>
  </p>
</td>
<td style="width: 241pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="321">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span lang="EN-US">location ^~ /image/{</span>
  </p>
</td>

<td style="width: 246.6pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="329">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">匹配常规字符串,不做正则表达式匹配检查</span>
  </p>
</td>
<td style="width: 241pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="321">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span lang="EN-US">location ~* \.(gif|jpg|jpeg)$ {</span>
  </p>
</td>

<td style="width: 246.6pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="329">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">正则匹配</span>
  </p>
</td>
<td style="width: 241pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="321">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span lang="EN-US">location /documents/ {</span>
  </p>
</td>

<td style="width: 246.6pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="329">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">匹配常规字符串,如果有正则,则优先匹配正则</span>
  </p>
</td>
<td style="width: 241pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="321">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span lang="EN-US">location / {</span>
  </p>
</td>

<td style="width: 246.6pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="329">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">所有</span><span lang="EN-US">location </span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">都不能匹配后的默认匹配</span>
  </p>
</td>

4.9.4

【测试】测试location的访问

4.9.4.1 

修改配置文件

4.9.4.2 

访问测试

4.10

rewrite 模块的使用地址重写

4.10.1

rewrite 重写模块

4.10.2

rewrite模块两个功能

4.10.3

方法一 使用if判断

4.10.4

方法二  再添加上一个区块

4.10.5

nginx rwite重写企业应用场景

可以调整用户浏览的URL,使其看起来更规范,合乎开发及产品人员的需求。

为了让搜索引擎收录网站内容,并让用户体验更好,企业会将动态URL地址伪装成静态地址提供服务。

网站换新域名后,让旧域名的访问跳转到新的域名上,例如:让京东的360buy换成了jd.com

4.11

nginx 的访问认证

4.11.1

修改nginx的相关配置文件

4.11.2

创建密码文件

  <td style="width: 367.1pt; border-top-width: 1pt; border-right-width: 1pt; border-bottom-width: 1pt; border-top-color: windowtext; border-right-color: windowtext; border-bottom-color: windowtext; border-left: none; background: #a6a6a6; padding: 0cm 5.4pt;" width="489">
    <p class="MsoNormal" style="text-align: center;" align="center">
      <strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">参数说明</span></strong>
    </p>
  </td>
</tr>

<tr>
  <td style="width: 155.7pt; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-top: none; padding: 0cm 5.4pt;" width="208">
    <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
      <span lang="EN-US">-c </span>
    </p>
  </td>
  
  <td style="width: 367.1pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="489">
    <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
      <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">创建一个新文件。</span>
    </p>
  </td>
</tr>

<tr>
  <td style="width: 155.7pt; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-top: none; padding: 0cm 5.4pt;" width="208">
    <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
      <span lang="EN-US">-n </span>
    </p>
  </td>
  
  <td style="width: 367.1pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="489">
    <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
      <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">不更新文件</span><span lang="EN-US">; </span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">显示结果。</span>
    </p>
  </td>
</tr>

<tr>
  <td style="width: 155.7pt; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-top: none; padding: 0cm 5.4pt;" width="208">
    <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
      <span lang="EN-US">-m </span>
    </p>
  </td>
  
  <td style="width: 367.1pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="489">
    <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
      <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">强制</span><span lang="EN-US">MD5</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">密码加密。</span>
    </p>
  </td>
</tr>

<tr>
  <td style="width: 155.7pt; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-top: none; padding: 0cm 5.4pt;" width="208">
    <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
      <span lang="EN-US">-d </span>
    </p>
  </td>
  
  <td style="width: 367.1pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="489">
    <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
      <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">强制</span><span lang="EN-US">CRYPT</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">加密密码(默认)。</span>
    </p>
  </td>
</tr>

<tr>
  <td style="width: 155.7pt; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-top: none; padding: 0cm 5.4pt;" width="208">
    <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
      <span lang="EN-US">-p </span>
    </p>
  </td>
  
  <td style="width: 367.1pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="489">
    <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
      <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">不加密密码(明文)。</span>
    </p>
  </td>
</tr>

<tr>
  <td style="width: 155.7pt; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-top: none; padding: 0cm 5.4pt;" width="208">
    <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
      <span lang="EN-US">-s </span>
    </p>
  </td>
  
  <td style="width: 367.1pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="489">
    <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
      <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">强制</span><span lang="EN-US">SHA</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">加密密码。</span>
    </p>
  </td>
</tr>

<tr>
  <td style="width: 155.7pt; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-top: none; padding: 0cm 5.4pt;" width="208">
    <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
      <span lang="EN-US">-b </span>
    </p>
  </td>
  
  <td style="width: 367.1pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="489">
    <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
      <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">使用命令行中的密码,而不是提示。(免交互)</span>
    </p>
  </td>
</tr>

<tr>
  <td style="width: 155.7pt; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-top: none; padding: 0cm 5.4pt;" width="208">
    <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
      <span lang="EN-US">-D </span>
    </p>
  </td>
  
  <td style="width: 367.1pt; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: windowtext; border-right-width: 1pt; border-right-color: windowtext; padding: 0cm 5.4pt;" width="489">
    <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
      <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">删除指定的用户。</span>
    </p>
  </td>
</tr>

4.11.3

更改密码文件权限

4.11.4

重启服务: 配置修改后要重启服务

4.11.5

访问测试

<

p class=“MsoNormal”> 

<li>
  <a href="#2_nginx">第2章 nginx 软件</a><ul>
    <li>
      <a href="#21">2.1 软件介绍</a>
    </li>
    <li>
      <a href="#22_NGINX">2.2 NGINX 软件特性</a><ul>
        <li>
          <a href="#221_HTTP">2.2.1 HTTP服务器的特色及优点:</a>
        </li>
        <li>
          <a href="#222_nginx">2.2.2 nginx功能特性</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#23_nginx">2.3 nginx软件的企业功能应用</a>
    </li>
    <li>
      <a href="#24_nginx">2.4 nginx软件的动态访问瓶颈</a><ul>
        <li>
          <a href="#241">2.4.1 与其他软件的对比</a>
        </li>
        <li>
          <a href="#242_select_epoll">2.4.2 最主要的区别(select & epoll)</a>
        </li>
        <li>
          <a href="#243_apache_selectnginx_epoll">2.4.3 apache select和nginx epoll技术对比图</a>
        </li>
      </ul>
    </li>
  </ul>
</li>

<li>
  <a href="#3_nginx">第3章 nginx的安装与使用</a><ul>
    <li>
      <a href="#31_nginx">3.1 nginx软件的编译安装步骤</a><ul>
        <li>
          <a href="#311">3.1.1 检查软件安装的系统环境</a>
        </li>
        <li>
          <a href="#312_nginxpcre-devel_openssl-devel">3.1.2 安装nginx的依赖包(pcre-devel openssl-devel)</a>
        </li>
        <li>
          <a href="#313_nginx">3.1.3 下载nginx软件</a>
        </li>
        <li>
          <a href="#314_www">3.1.4 创建管理用户 www</a>
        </li>
        <li>
          <a href="#315_nginx">3.1.5  nginx软件编译安装过程</a><ul>
            <li>
              <a href="#3151">3.1.5.1  注意</a>
            </li>
            <li>
              <a href="#3152">3.1.5.2  编译安装软件</a>
            </li>
          </ul>
        </li>
        
        <li>
          <a href="#316">3.1.6 创建软连接</a>
        </li>
        <li>
          <a href="#317_nginxconf">3.1.7 精简化nginx.conf 主配置文件内容</a>
        </li>
        <li>
          <a href="#318">3.1.8 启动程序</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#31_nginx-2">3.1 nginx 目录结构</a>
    </li>
    <li>
      <a href="#32_nginxconf">3.2 nginx.conf 配置文件说明</a><ul>
        <li>
          <a href="#321">3.2.1 站点目录与首页文件概 </a>
        </li>
        <li>
          <a href="#322">3.2.2 配置文件详解 </a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#33_nginx">3.3 【常见错误】nginx软件的编译安装常见错误说明</a><ul>
        <li>
          <a href="#331_nginx">3.3.1 nginx软件安装过程中遇到的问题</a>
        </li>
        <li>
          <a href="#332_nginx">3.3.2 nginx软件启动过程中遇到的问题</a>
        </li>
        <li>
          <a href="#333_Nginx_nginxemerggetpwnamnginxfailed">3.3.3 启动 Nginx 时如下报错"nginx:[emerg]getpwnam(“nginx”〉failed"</a>
        </li>
        <li>
          <a href="#334_pcregccyum">3.3.4 编译安装pcre编译软件时,gcc不全导致报错(本文使用yum安装不存在此问题)。</a>
        </li>
        <li>
          <a href="#335_nginxapplication">3.3.5 nginx软件编译安装后,看不到程序目录(/application)</a>
        </li>
        <li>
          <a href="#336_nginx">3.3.6 nginx软件排查问题三部曲说明</a>
        </li>
        <li>
          <a href="#337_403">3.3.7 【注意】403状态码出现情况原因</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#34_nginx">3.4 nginx软件使用命令参数</a><ul>
        <li>
          <a href="#341_nginx">3.4.1 nginx 启动方法</a>
        </li>
        <li>
          <a href="#342_nginx">3.4.2 nginx 停止方法</a>
        </li>
        <li>
          <a href="#343_nginx">3.4.3 nginx 重启方法 (平滑重启)</a>
        </li>
        <li>
          <a href="#344">3.4.4 检查配置文件语法是否正确</a>
        </li>
        <li>
          <a href="#345_-V_V">3.4.5 显示配置参数  -V (大写V)</a>
        </li>
        <li>
          <a href="#346_nginx">3.4.6 nginx软件使用过程中深入说明</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#35_nginx">3.5 nginx软件静态页面编写过程</a>
    </li>
  </ul>
</li>

<li>
  <a href="#4_nginx">第4章 nginx进阶 --虚拟主机配置</a><ul>
    <li>
      <a href="#41_nginx">4.1 【企业要求】需要按照以前nginx服务编译安装过程安装</a><ul>
        <li>
          <a href="#411">4.1.1 【语法检查】检查配置文件</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#42_--nginx">4.2 首页文件不存在--利用nginx服务搭建文件共享服务器</a><ul>
        <li>
          <a href="#421_curl403">4.2.1 进行curl时,报403错误,因为没有首页文件信息</a>
        </li>
        <li>
          <a href="#422_autoindex_on">4.2.2 autoindex on参数实践</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#43">4.3 【概念】虚拟主机的概念和类型</a><ul>
        <li>
          <a href="#431">4.3.1 虚拟主机概念</a>
        </li>
        <li>
          <a href="#432">4.3.2 虚拟主机类型</a>
        </li>
        <li>
          <a href="#433_Nginx">4.3.3 Nginx配置虚拟主机的步骤如下(适合各类虚拟主机类型)</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#44">4.4 【实践】虚拟主机配置</a><ul>
        <li>
          <a href="#441">4.4.1 基于域名的虚拟主机</a>
        </li>
        <li>
          <a href="#442">4.4.2 基于端口的虚拟主机</a>
        </li>
        <li>
          <a href="#443_IP">4.4.3 基于IP的虚拟主机</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#45_nginx">4.5 【规范化配置】nginx配置文件企业规范化</a><ul>
        <li>
          <a href="#451">4.5.1 第一个里程碑:  创建虚拟主机配置文件存储目录</a>
        </li>
        <li>
          <a href="#452">4.5.2 第二个里程碑: 生产虚拟主机配置文件</a>
        </li>
        <li>
          <a href="#453_nginx">4.5.3 第三个里程碑: 修改nginx配置文件使之加载识别虚拟主机配置文件</a>
        </li>
        <li>
          <a href="#454">4.5.4 重启服务</a>
        </li>
        <li>
          <a href="#455">4.5.5 检查监听端口</a>
        </li>
        <li>
          <a href="#456">4.5.6 查看配置文件的加载顺序</a>
        </li>
        <li>
          <a href="#457_inculdeconf">4.5.7 【优化】调整 inculde的加载顺序,指定第一个加载为conf</a>
        </li>
        <li>
          <a href="#458">4.5.8 重启服务</a>
        </li>
        <li>
          <a href="#459">4.5.9 说明;</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#46">4.6 别名的配置</a>
    </li>
    <li>
      <a href="#47_status">4.7 status 状态模块</a><ul>
        <li>
          <a href="#471">4.7.1 状态模块的配置</a>
        </li>
        <li>
          <a href="#472">4.7.2 状态模块说明</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#48_nginx">4.8 nginx的日志功能</a><ul>
        <li>
          <a href="#481">4.8.1 定义错误日志信息</a>
        </li>
        <li>
          <a href="#482">4.8.2 访问日志配置</a>
        </li>
        <li>
          <a href="#483">4.8.3 【重要】访问日志信息说明</a>
        </li>
        <li>
          <a href="#484">4.8.4 日志的切割</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#49_location">4.9 企业需求解决(location应用)</a><ul>
        <li>
          <a href="#491_--location">4.9.1 需求处理 --location的应用</a>
        </li>
        <li>
          <a href="#492_location">4.9.2 location 语法</a>
        </li>
        <li>
          <a href="#493">4.9.3 官方配置示例</a>
        </li>
        <li>
          <a href="#494_location">4.9.4 【测试】测试location的访问</a><ul>
            <li>
              <a href="#4941">4.9.4.1  修改配置文件</a>
            </li>
            <li>
              <a href="#4942">4.9.4.2  访问测试</a>
            </li>
          </ul>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#410_rewrite">4.10 rewrite 模块的使用--地址重写</a><ul>
        <li>
          <a href="#4101_rewrite">4.10.1 rewrite 重写模块</a>
        </li>
        <li>
          <a href="#4102_rewrite">4.10.2 rewrite模块两个功能</a>
        </li>
        <li>
          <a href="#4103_if">4.10.3 方法一 使用if判断</a>
        </li>
        <li>
          <a href="#4104">4.10.4 方法二  再添加上一个区块</a>
        </li>
        <li>
          <a href="#4105_nginx_rwite">4.10.5 nginx 的rwite重写企业应用场景</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#411_nginx">4.11 nginx 的访问认证</a><ul>
        <li>
          <a href="#4111_nginx">4.11.1 修改nginx的相关配置文件</a>
        </li>
        <li>
          <a href="#4112">4.11.2 创建密码文件</a>
        </li>
        <li>
          <a href="#4113">4.11.3 更改密码文件权限</a>
        </li>
        <li>
          <a href="#4114">4.11.4 重启服务: 配置修改后要重启服务</a>
        </li>
        <li>
          <a href="#4115">4.11.5 访问测试</a>
        </li>
      </ul>
    </li>
  </ul>
</li>