nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server.
nginx是一个http和反转代理服务器,还可以用作邮件代理,TCP/UDP代理服务器。
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
Window平台下(如果linux下将nginx当成一个应用使用的话,用法和window平台下差不多,如果在linux系统上作为服务使用,则区别较大):
下载安装
window平台下,下载nginx-1.15.12的压缩包,解压即可。
使用
windows平台下,在解压目录下,启动命令
start nginx
或者直接
./nginx
启动tasklist命令行工具包来查看进程
tasklist /fi "imagename eq nginx.exe"
其他命令
nginx/Windows runs as a standard console application (not a service), and it can be managed using the following commands:
- nginx -s stop fast shutdown
- nginx -s quit graceful shutdown,This command should be executed under the same user that started nginx
- nginx -s reload changing configuration, starting new worker processes with a new configuration, graceful shutdown of old worker processes
- nginx -s reopen re-opening log files
nginx的配置文件在 ./conf/nginx.conf 中,Configuration File文件的结构:
nginx consists of modules which are controlled by directives specified in the configuration file. Directives are divided into simple directives and block directives. A simple directive consists of the name and parameters separated by spaces and ends with a semicolon (;
). A block directive has the same structure as a simple directive, but instead of the semicolon it ends with a set of additional instructions surrounded by braces ({
and }
). If a block directive can have other directives inside braces, it is called a context (examples: events, http,server, and location).
Directives placed in the configuration file outside of any contexts are considered to be in the main context. The events
and http
directives reside in the main
context, server
in http
, and location
in server
.
The rest of a line after the #
sign is considered a comment.
Linux平台下(以Centos为例,此时nginx是作为一项服务):
安装
yum install epel-release
yum install nginx
服务的管理 开启 查询 停止 重启
systemctl start nginx
systemctl status nginx
systemctl stop nginx
systemctl restart nginx
重新载入nginx的配置文件(在修改配置文件之后)
systemctl reload nginx
nginx的主要配置文件在 /etc/nginx
核心配置文件是 /etc/nginx/nginx.conf
日志文件是在 /var/log/nginx
上面都是直接使用安装包,如果对ngnix有较高的定制需求,需要自己编译打包,还可以下载丰富的第三方插件。
参考:
http://nginx.org/en/docs/beginners_guide.html
https://linuxize.com/post/how-to-install-nginx-on-centos-7/
End