Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions 介绍/控制nginx.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 控制 nginx

- [配置变更](#配置变更)
- [日志轮转](#日志轮转)
- [升级可执行文件](#升级可执行文件)

可以用信号控制 nginx。默认情况下,主进程(Master)的 pid 写在 `/use/local/nginx/logs/nginx.pid` 文件中。这个文件的位置可以在配置时更改或者在 nginx.conf 文件中使用 `pid` 指令更改。Master 进程支持以下信号:

信号 | 作用
Expand All @@ -18,13 +22,13 @@ Worker 进程也是可以用信号控制的,尽管这不是必须的。支持
TERM, INT | 快速关闭
QUIT | 正常关闭
USR1 | 重新打开日志文件
WINCH | 调试异常终止(需要开启 `debug_points`
WINCH | 调试异常终止(需要开启 [debug_points](http://nginx.org/en/docs/ngx_core_module.html#debug_points)

## 配置变更

为了让 nginx 重新读取配置文件,应将 `HUP` 信号发送给 Master 进程。Master 进程首先会检查配置文件的语法有效性,之后尝试应用新的配置,即打开日志文件和新的 socket。如果失败了,它会回滚更改并继续使用旧的配置。如果成功,它将启动新的 Worker 进程并向旧的 Worker 进程发送消息请求它们正常关闭。旧的 Worker 进程关闭监听 socket 并继续为旧的客户端服务,当所有就的客户端被处理完成,旧的 Worker 进程将被关闭。
为了让 nginx 重新读取配置文件,应将 `HUP` 信号发送给 Master 进程。Master 进程首先会检查配置文件的语法有效性,之后尝试应用新的配置,即打开日志文件和新的 socket。如果失败了,它会回滚更改并继续使用旧的配置。如果成功,它将启动新的 Worker 进程并向旧的 Worker 进程发送消息请求它们正常关闭。旧的 Worker 进程关闭监听 socket 并继续为旧的客户端服务,当所有旧的客户端被处理完成,旧的 Worker 进程将被关闭。

我们来举例说明一下。 想象一下,nginx 是在 FreeBSD 4.x 命令行上运行的
我们来举例说明一下。 假设 nginx 是在 FreeBSD 4.x 命令行上运行的

```bash
ps axw -o pid,ppid,user,%cpu,vsz,wchan,command | egrep '(nginx|PID)'
Expand Down
4 changes: 2 additions & 2 deletions 介绍/记录日志到syslog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 记录日志到 syslog

`error_log``access_log` 指令支持把日志记录到 syslog。以下配置参数将使 nginx 日志记录到 syslog:
[error_log](http://nginx.org/en/docs/ngx_core_module.html#error_log)[access_log](http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log) 指令支持把日志记录到 syslog。以下配置参数将使 nginx 日志记录到 syslog:

```yaml
server=address
Expand All @@ -19,7 +19,7 @@ facility=string
severity=string
```

> 设置 `access_log` 的消息严重程度,在 [RFC3164](https://tools.ietf.org/html/rfc3164#section-4.1.1) 中定义。可能值与 `error_log` 指令的第二个参数( `level`,级别)相同,默认是 `info`。错误消息的严重程度由 nginx 确定,因此在 `error_log` 指令中将忽略该参数。
> 设置 [access_log](http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log) 的消息严重程度,在 [RFC3164](https://tools.ietf.org/html/rfc3164#section-4.1.1) 中定义。可能值与 [error_log](http://nginx.org/en/docs/ngx_core_module.html#error_log) 指令的第二个参数( `level`,级别)相同,默认是 `info`。错误消息的严重程度由 nginx 确定,因此在 `error_log` 指令中将忽略该参数。

```
tag=string
Expand Down
7 changes: 5 additions & 2 deletions 介绍/调试日志.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# 调试日志

- [为指定客户端做调试日志](#为指定客户端做调试日志)
- [记录日志到循环内存缓冲区](#记录日志到循环内存缓冲区)

要开启调试日志,需要在编译 Nignx 时增加如下配置:

```bash
./configure --with-debug ...
```

之后应该使用 `error_log` 指令设置调试级别:
之后应该使用 [error_log](http://nginx.org/en/docs/ngx_core_module.html#error_log) 指令设置调试级别:

```nginx
error_log /path/to/log debug;
Expand All @@ -18,7 +21,7 @@ error_log /path/to/log debug;
configure arguments: --with-debug ...
```

预构建 Linux 包为 nginx-debug 二进制文件的调试日志提供了开箱即用的支持,可以使用命令运行。
预构建 [Linux](http://nginx.org/en/linux_packages.html) 包为 nginx-debug 二进制文件的调试日志提供了开箱即用的支持,可以使用命令运行。

```bash
service nginx stop
Expand Down
2 changes: 1 addition & 1 deletion 介绍/连接处理方式.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 连接处理方式

nginx 支持多种连接处理方式,每一种方式是否可用取决于所用的平台。在支持几种方式的平台上,nginx 会自动选择最有效的方式,然而,如果您需要明确指定使用哪一种方式,可以使用 `use` 指令指定。
nginx 支持多种连接处理方式,每一种方式是否可用取决于所用的平台。在支持几种方式的平台上,nginx 会自动选择最有效的方式,然而,如果您需要明确指定使用哪一种方式,可以使用 [use](http://nginx.org/en/docs/ngx_core_module.html#use) 指令指定。

支持以下集中处理方式:

Expand Down