Nginx编译安装

参考原文:https://www.cnblogs.com/zhang-shijie/p/5294162.html

一、介绍

Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好。

二、环境准备

yum install -y gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel 

三、安装

1、创建Ningx用户

groupadd -r nginx
useradd -r -g nginx nginx

2、解压安装包

[root@master opt]# tar  xvf nginx-1.12.2.tar.gz
[root@master opt]# cd nginx-1.12.2

3、编译nginx

./configure  \
--prefix=/usr/local/nginx  \
--lock-path=/var/lock/nginx.lock  \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi

4、安装

make
make install 
mkdir -p /var/tmp/nginx/client/

 

四、nginx操作

1、启动、重读配置文件和关闭服务

# /usr/local/nginx/sbin/nginx                  #启动 服务
# /usr/local/nginx/sbin/nginx -t               #修改配置文件后检查语法
# /usr/local/nginx/sbin/nginx -s  reload       #不停止服务重读配置文件
# /usr/local/nginx/sbin/nginx -s stop          #停止服务 

2、验证端口是否开启

[root@master conf]# lsof -i:18080
COMMAND   PID  USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
nginx   22588  root    6u  IPv4 14633566      0t0  TCP *:18080 (LISTEN)
nginx   22589 nginx    6u  IPv4 14633566      0t0  TCP *:18080 (LISTEN)
[root@master conf]# ps -ef|grep nginx
root     22588     1  0 Feb24 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx    22589 22588  0 Feb24 ?        00:00:00 nginx: worker process 

3、访问页面

http://192.168.1.135:18080/

4、通过给nginx的主进程ID号发送信号启动或停止nginx:

[root@Server1 nginx]# kill  -QUIT 13337  #平缓关闭Nginx,即不再接受新的请求,但是等当前请求处理完毕后再关闭Nginx。
[root@Server1 nginx]# kill  -TERM  21665 #快速停止Nginx服务
[root@Server1 nginx]# kill  -HUP 21703 #使用新的配置文件启动进程然后平缓停止原有的nginx进程,即平滑重启。 
[root@Server1 nginx]# kill -USR1 21703   #重新打开配置文件,用于nginx 日志切割
日期切割的脚本:
#!/bin/bash
PID=`cat /var/run/nginx/nginx.pid`
mv   /var/log/nginx/access.log   /var/log/nginx/`date  +%Y_%m_%d:%H:%M:%S`.access.log
kill -USR1 $PID
[root@Server1 nginx]# kill -USR2 21703   #使用新版本的nginx文件启动服务,然后在平缓停止原有的nginx服务,即平滑升级。
[root@Server1 nginx]# kill -WINCH  21703  #平滑停止nginx的工作进程,用于nginx平滑升级。

 五、开机自启动

即在rc.local增加启动代码就可以了。

vi /etc/rc.local 增加一行 /usr/local/nginx/sbin/nginx 设置执行权限:

chmod 755 rc.local

posted @ 2018-02-24 16:19  Gringer  阅读(141)  评论(0)    收藏  举报