Centos源码编译nginx

CentOS下编译安装 Nginx

1.安装依赖

$ yum -y install gcc gcc-c++ autoconf automake make
$ yum -y install zlib zlib-devel openssl 
$ yum -y install openssl-devel pcre pcre-devel

2.安装 Nginx

$ wget  http://nginx.org/download/nginx-1.13.0.tar.gz  
$ tar zxvf nginx-1.13.0.tar.gz
$ cd nginx-1.13.0
# 编译安装(携带编译目录,并且安装ssl 等模块) 二选一
$ ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module
# 只选择编译目录,不安装任何模块,二选一
$ ./configure --prefix=/usr/local/nginx
$ make && make install

3.运行 configure 后可以看到一大串配置信息:

nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"

4.检测是否成功

$ /usr/local/nginx/sbin/nginx -V
# configure arguments后面--prefix后面必须要有安装路径
nginx version: nginx/1.13.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module ......

5.检查配置

$ nginx -t

6.读取nginx配置

$ nginx -c /usr/local/nginx/conf/nginx.conf

7.复制一份nginx.pid(一定要备份,你以后绝对用得着的)

$ nginx -t
$ cp /usr/local/nginx/logs/nginx.pid nginx_bak.pid.bak

8.查看 nginx 进程

$ ps aux | grep nginx