Nginx-编译安装_启动_停止

作者:聂勇 欢迎转载,请保留作者信息并说明文章来源!
Nginx

一、预备 | Prerequisites

  • CentOS5 / RedHat5 /CentOS6 / RedHat6
  • GCC-4.1.2
  • Nginx-1.9.2
  • pcre-8.21
  • zlib-1.2.5
  • openssl-1.0.2c

二、配置依赖组件 | Setup Dependents

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 进入存放下载文件的目录
cd ~/download
# PCRE源码下载和解压
wget http://sourceforge.net/projects/pcre/files/pcre/8.21/pcre-8.21.tar.gz/download
tar -zxvf pcre-8.21.tar.gz -C ../build/
# zlib源码下载和解压
wget http://sourceforge.net/projects/libpng/files/zlib/1.2.5/zlib-1.2.5.tar.gz/download?use_mirror=nchc&download=
tar -zxvf zlib-1.2.5.tar.gz -C ../build/
# OpenSSL源码下载和解压
wget --no-check-certificate https://www.openssl.org/source/openssl-1.0.2c.tar.gz
tar -zxvf openssl-1.0.2c.tar.gz -C ../build/

三、安装Nginx | Install Nginx

1、下载Nginx源码并解压。

1
2
3
4
5
6
# 进入存放下载文件的目录
cd ~/download
# 下载源码并解压
wget http://nginx.org/download/nginx-1.9.2.tar.gz
tar -zxvf nginx-1.9.2.tar.gz -C ../build/

2、编译三步曲。
1)编译配置。

1
2
3
4
5
6
7
8
9
./configure --prefix=/home/sdkserver/local/nginx-1.9.2 \
--with-pcre=/home/sdkserver/build/pcre-8.21 --with-pcre-jit \
--with-zlib=/home/sdkserver/build/zlib-1.2.5 \
--with-openssl=/home/sdkserver/build/openssl-1.0.2c --with-http_ssl_module \
--http-client-body-temp-path=/home/sdkserver/local/nginx-1.9.2/temp/body \
--http-fastcgi-temp-path=/home/sdkserver/local/nginx-1.9.2/temp/fastcgi \
--http-proxy-temp-path=/home/sdkserver/local/nginx-1.9.2/temp/proxy \
--http-scgi-temp-path=/home/sdkserver/local/nginx-1.9.2/temp/scgi \
--http-uwsgi-temp-path=/home/sdkserver/local/nginx-1.9.2/temp/uwsgi

配置成功,系统输出类似如下信息:

Configuration summary
  + using PCRE library: /home/sdkserver/build/pcre-8.21
  + using OpenSSL library: /home/sdkserver/build/openssl-1.0.2c
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using zlib library: /home/sdkserver/build/zlib-1.2.5

  nginx path prefix: "/home/sdkserver/local/nginx-1.9.2"
  nginx binary file: "/home/sdkserver/local/nginx-1.9.2/sbin/nginx"
  nginx configuration prefix: "/home/sdkserver/local/nginx-1.9.2/conf"
  nginx configuration file: "/home/sdkserver/local/nginx-1.9.2/conf/nginx.conf"
  nginx pid file: "/home/sdkserver/local/nginx-1.9.2/logs/nginx.pid"
  nginx error log file: "/home/sdkserver/local/nginx-1.9.2/logs/error.log"
  nginx http access log file: "/home/sdkserver/local/nginx-1.9.2/logs/access.log"
  nginx http client request body temporary files: "/home/sdkserver/local/nginx-1.9.2/temp/body"
  nginx http proxy temporary files: "/home/sdkserver/local/nginx-1.9.2/temp/proxy"
  nginx http fastcgi temporary files: "/home/sdkserver/local/nginx-1.9.2/temp/fastcgi"
  nginx http uwsgi temporary files: "/home/sdkserver/local/nginx-1.9.2/temp/uwsgi"
  nginx http scgi temporary files: "/home/sdkserver/local/nginx-1.9.2/temp/scgi"

2)编译安装。

1
2
make
make install

四、Nginx启动和停止 | How to start and stop nginx

1、启动Nginx。

1
./sbin/nginx -c ./conf/nginx.conf

2、停止Nginx。
1)安全停止。

1
kill -QUIT [Nginx主进程号]


1
./sbin/nginx -s quit

2)快速停止。

1
kill -TERM [Nginx主进程号]


1
kill -INT [Nginx主进程号]


1
./sbin/nginx -s stop

3、重启Nginx。

1
kill -HUP [Nginx主进程号]


1
./sbin/nginx -s reload

4、检查配置文件的语法是否正确。

1
./sbin/nginx -t -c ./conf/nginx.conf

五、参考资料 | References