1.下载nginx
地址:https://nginx.org/en/download.html
2.登录服务器,创建app目录,并在app目录下下载Nginx,并解压
执行命令:
$ cd /usr/local
$ mkdir app
$ cd app
$ mkdir nginx
$ cd nginx
$ wget https://nginx.org/download/nginx-1.16.0.tar.gz
$ tar -zxvf nginx-1.16.0.tar.gz
3.预备编译环境
安装make,执行命令如下:
$ yum -y install gcc automake autoconf libtool make
安装g++,执行命令如下:
$ yum install gcc gcc-c++
4.安装Nginx依赖包(zlib、pcre、openssl)
1)gzip模块需zlib库,本次安装当前最新版本zlib-1.2.11
$ cd /usr/local/app
$ mkdir zlib
$ cd zlib
$ wget https://downloads.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz
$ tar -zxvf zlib-1.2.11.tar.gz
$ cd zlib-1.2.11
$ ./configure
$ make
$ make install
2)rewrite模块需pcre库,本次安装pcre-8.43版本
$ cd /usr/local/app
$ mkdir pcre
$ cd pcre
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.43.tar.gz
$ tar -zxvf pcre-8.43.tar.gz
$ cd pcre-8.43
$ ./configure
$ make
$ make install
3)ssl功能需openssl库,版本openssl-1.0.2s
$ cd /usr/local/app
$ mkdir openssl
$ cd openssl
$ wget https://www.openssl.org/source/openssl-1.0.2s.tar.gz
$ tar -zxvf openssl-1.0.2s.tar.gz
$ cd openssl-1.0.2s
$ ./config
$ make
$ make install
5.安装Nginx
执行命令:
$ cd /usr/local/app/nginx-1.16.0
$ ./configure --prefix=/usr/local/app/nginx
--sbin-path=/usr/local/app/nginx/nginx
--conf-path=/usr/local/app/nginx/nginx.conf
--pid-path=/usr/local/app/nginx/nginx.pid
--with-http_ssl_module
--with-pcre=/usr/local/app/pcre/pcre-8.43
--with-zlib=/usr/local/app/zlib/zlib-1.2.11
--with-openssl=/usr/local/app/openssl/openssl-1.0.2s
(输入时排成一行,间隔1个空格)
$ make
$ make install
6.启动Nginx
执行命令:
$ cd /usr/local/app/nginx
$ ./nginx (启动nginx)
$ ./nginx -s reload (重启 nginx)
$ ./nginx -s stop (停止 nginx)
7.访问Nginx
浏览器输入:http://xxx.xxx.x.xxx/