ubuntu下编译安装nginx

1.安装编译需要用到的库和工具

apt-get install build-essential libtool gcc automake autoconf make

2.安装pcre,支持重写rewrite功能

源码下载地址:https://ftp.pcre.org/pub/pcre/
wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz 
tar -zxvf pcre-8.40.tar.gz
cd pcre-8.40.tar.gz
./configure 
make && make install

3.安装zlib, 支持gzip压缩

源码下载地址:http://zlib.net
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make && make install

4.安装ssl

源码地址:https://www.openssl.org/source/
wget https://www.openssl.org/source/openssl-1.0.2o.tar.gz
tar -zxvf openssl-1.0.2o.tar.gz
cd openssl-1.0.2o
./config
make && make install

5、安装Nginx:

源码地址:http://nginx.org/en/download.html
wget http://nginx.org/download/nginx-1.13.12.tar.gz
tar -zxvf nginx-1.13.12.tar.gz
cd nginx-1.13.12.tar.gz
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

预编译:

./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
-pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.40 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.0.2o

编译安装:

make && make install

安装完成: 启动目录:

/usr/local/nginx/sbin/nginx -s reload 

查看是否运行:

ps-ef|grep nginx