Nginx:基础

简介

官网介绍如下:

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系统上作为服务使用,则区别较大,区别见下面):

下载安装

 windows 平台下,下载nginx-1.15.12的压缩包,解压即可。linux 平台也可以下载对应的二进制文件。

使用

在解压目录下,启动命令

start nginx

或者

./nginx

如果是 windows 平台一定要在 do s窗口启动,不要直接双击 nginx.exe,这样会导致修改配置后重启、停止nginx无效,需要手动关闭任务管理器内的所有nginx进程,再启动才可以。

windows 平台下启动 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: eventshttp,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/

正向代理和反向代理区别 https://www.cnblogs.com/taostaryu/p/10547132.html

posted @ 2019-04-18 17:41  colin220  阅读(159)  评论(0编辑  收藏  举报