【Nginx系列】Nginx编译与安装

Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。Nginx是由Igor Sysoev为俄罗斯访问第二的Rambler.ru站点开发的.

一、Nginx的安装

下载地址:http://nginx.org/download/nginx-1.12.2.zip

cd /usr/local/bin

wget http://nginx.org/download/nginx-1.12.2.zip

unzip http://nginx.org/download/nginx-1.12.2.zip

cd nginx-1.12.2

./configure --prefix=/usr/local/nginx   #可能会缺少部分模块

yum install pcre pcre-devel    #安装正则表达式模块的库 装完之后记得重新执行上一个命令

make && make install 

#cd /usr/local 看是否有nginx

二、启动nginx

cd /usr/local 

ls

4个目录:conf --配置文件目录

                 html   --网页文件

                 logs   --日志文件

                 sbin    --主要二进制程序

cd sbin

./sbin/nginx

可能问题:nginx:[emerg] bind() to 0.0.0.0:80 failed (98:Address already in  use)  端口被占用

ps -aux |grep 80

netstat -antp

kill -9 进程号(pkill -9 http)

 解决方案:关闭占用端口的服务或更换端口    

三、Nginx的信号控制与进程管理

  https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/

Nginx信号量
TERM INT  Quick shutdown
QUIT Graceful shutdown优雅关闭进程,即等请求结束之后再关闭
KILL Halts a stubborn process
HUP

Configuration reload 

Start the new worker processes witha new configuration

Gracefully shutdown the old worker processes

改变配置文件,平滑的重启配置文件

USR1 Reopen the log file 重读日志,再日志安月/日分割时有用
USR2 Upgrade Executable on the fly 平滑的升级
WINCH Gracefully shutdown the worker processes优雅关闭旧的进程(配合USR2来进行升级)

具体语法:

kill -信号选项 nginx的主进程号

eg:kill -HUP XXXX

kill -信号控制 `cat /xxx/path/log/nginx.pid` 

kill  -USR1 `cat /xxx/path/log/nginx.pid`

 

posted @ 2018-04-01 17:46  霓裳梦竹  阅读(203)  评论(0编辑  收藏  举报