安装编译环境和必要的库
[root@localhost ~]# yum -y install gcc gcc-c++ autoconf automake libtool make cmake
[root@localhost ~]# yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
说明:
zlib: 为nginx提供gzip模块,需要zlib库支持
openssl: 为nginx提供ssl功能
pcre: 为支持地址重写rewrite功能,有一些操作系统使用yum install pcre-devel安装,由于缺乏包,而安装失败,因此需要手动安装
手动安装pcre
[root@localhost ~]#wget https://sourceforge.net/projects/pcre/files/pcre/8.39/pcre-8.39.tar.gz
[root@localhost ~]#tar -zxvf pcre-8.39.tar.gz
[root@localhost ~]#cd pcre-8.39
[root@localhost ~]#./configure
[root@localhost ~]#make
[root@localhost ~]#make install
创建用来运行nginx的用户及组
[root@localhost ~]#groupadd nginx
[root@localhost ~]#useradd -M -s /sbin/nologin -g nginx nginx
说明
-g参数为nginx用户指定了一个组。
-M参数保证其不自动生成home目录。
编译安装Nginx
[root@localhost ~]#wget http://nginx.org/download/nginx-1.10.1.tar.gz
[root@localhost ~]#ls
[root@localhost ~]#tar -zxvf nginx-1.10.1.tar.gz
[root@localhost ~]#cd nginx-1.10.1
[root@localhost ~]#ls
[root@localhost ~]#./configure --prefix=/usr/local/nginx --with-http_ssl_module --user=nginx --group=nginx --with-pcre
[root@localhost ~]#make
[root@localhost ~]#make install
启动
[root@localhost ~]# /usr/local/nginx/sbin/nginx 启动
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s stop 停止
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload 重新载入
[root@localhost ~]# /usr/local/nginx/sbin/nginx -v 查看版本
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t 测试配置文件是否正常
[root@localhost ~]# pkill nginx 强制关闭
查看安装状态
[root@localhost ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.10.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (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 --user=nginx --group=nginx --with-pcre