ngnix虽然工作中也在用,但是从来没有完全去了解过,现在从基本的开始了解nginx,故有此翻译。
Beginner’s Guide
入门指导
This guide gives a basic introduction to nginx and describes some simple tasks that can be done with it. It is supposed that nginx is already installed on the reader’s machine. If it is not, see the Installing nginx page. This guide describes how to start and stop nginx, and reload its configuration, explains the structure of the configuration file and describes how to set up nginx to serve out static content, how to configure nginx as a proxy server, and how to connect it with a FastCGI application.
nginx has one master process and several worker processes. The main purpose of the master process is to read and evaluate configuration, and maintain worker processes. Worker processes do actual processing of requests. nginx employs event-based model and OS-dependent mechanisms to efficiently distribute requests among worker processes. The number of worker processes is defined in the configuration file and may be fixed for a given configuration or automatically adjusted to the number of available CPU cores (see worker_processes).
The way nginx and its modules work is determined in the configuration file. By default, the configuration file is named nginx.conf and placed in the directory /usr/local/nginx/conf, /etc/nginx, or /usr/local/etc/nginx.
该指导简单介绍了ngnix和描述了一些nginx可以做的简单任务。再此假设读者机器上已经安装了nginx。如果没有,请看安装nginx页面介绍。该指导描述了如何开启,停止nginx,怎么重新加载配置文件,解释了配置文件的结构,介绍了如何建立nginx对外发布静态内容,如何配置nginx来作为代理服务器,怎么通过使用FastCGI应用连接它。
nginx有一个主进程(下文中统称master进程)和多个工作进程(下文中统称为worker进程)。master进程的目的是读取,评估配置文件,维护worker进程。worker进程通常处理请求。nginx采用基于事件驱动模型和依赖于操作系统的机制来有效地在worker进程中分发请求。worker进程数量定义在配置文件中,可以修改为指定的配置或者自动适配为可用的cup核心数量(worker进程)
nginx和它的各个模块的工作方式定义在配置文件中。默认情况下,配置文件命名为nginx.conf,放在/usr/local/nginx/conf,/etc/nginx或者/usr/local/etc/nginx目录下。
Starting, Stopping, and Reloading Configuration
开启,停止,重载配置
To start nginx, run the executable file. Once nginx is started, it can be controlled by invoking the executable with the -s parameter. Use the following syntax:
nginx -s signal
Where signal may be one of the following:
stop — fast shutdown
quit — graceful shutdown
reload — reloading the configuration file
reopen — reopening the log files
For example, to stop nginx processes with waiting for the worker processes to finish serving current requests, the following command can be executed:
nginx -s quit
This command should be executed under the same user that started nginx.
Changes made in the configuration file will not be applied until the command to reload configuration is sent to nginx or it is restarted. To reload configuration, execute:
nginx -s reload
为了开启nginx,可以运行可执行文件。一旦nginx启动,可以通过使用-s参数调用可执行文件来控制它。使用下面的语法:
nginx -s signal
信号量可以是下面的任意一种:
stop - 快速停止
quit - 优雅地停止
reload - 重载配置文件
reopen - 重新打开日志文件
例如,为了停止正在等待worker进程完成当前请求的nginx进程,可以执行以下命令:
nginx -s quit
此命令应该被开启nginx的用户执行。
在配置文件中的修改不会被应用直到重新载入配置的命令被发送到nginx或者被重启。为了重载配置,执行:
nginx -s reload
Once the master process receives the signal to reload configuration, it checks the syntax validity of the new configuration file and tries to apply the configuration provided in it. If this is a success, the master process

本文是一篇关于nginx的入门指南,详细介绍了如何启动、停止和重载nginx配置,理解配置文件结构,以及如何配置nginx来服务静态内容和作为简单的代理服务器。通过配置,nginx可以为静态文件和FastCGI应用提供服务,实现请求的高效分发。
最低0.47元/天 解锁文章
821

被折叠的 条评论
为什么被折叠?



