linux下nginx编译安装(抄别人的,方便查看)

原路径:https://blog.csdn.net/youcijibi/article/details/75050993

正式开始前,编译环境gcc g++ 开发库之类的需要提前装好。

如果是ububtu平台初始安装编译安装则使用如下指令:

apt-get install build-essential

apt-get installlibtool
如果是centos则如下:
当没有make时:

安装make:

yum -y install gcc automake autoconf libtool make
 
安装c++编译环境

yum -y install gcc-c++

下面正式开始
---------------------------------------------------------------------------
一般我们都需要先装pcre, zlib,openssl,前者为了重写rewrite,后者为了gzip压缩,在后者是为了使用ssl
1,选择源码包所存放的目录,这里为/usr/local/src
2,所有依赖的安装目录为/usr/local/related

安装pcre:

cd/usr/local/src

wget https://sourceforge.net/projects/pcre/files/pcre/8.41/pcre-8.41.tar.gz/

tar-zxvfpcre-8.41.tar.gz

cd pcre-8.41

./configure --prefix=/usr/local/related/pcre

make

makeinstall
如果安装的是bz2 ,提示tar (child): bzip2:无法 exec: 没有那个文件或目录 tar (child): Error is not recoverable: exiting now

缺少bzip2包
yum install -y bzip2

然后

tar -jxf xxx.tar.bz2即可

安装zlib
cd /usr/local/src

wget http://zlib.net/zlib-1.2.11.tar.gz  --这个玩意更新很快,旧版地址会被官方更新,所以只能打开官网找最新的下载

tar -zxvf zlib-1.2.8.tar.gz

cdzlib-1.2.8

./configure --prefix=/usr/local/related/zlib

make

make install

安装openssl
cd /usr/local/src

wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz

tar-zxvf openssl-1.0.1t.tar.gz

config --prefix=/usr/local/related/openssl
make
make install

安装它的时候或者安装mysql的依赖包bison 的时候都需要perl的支持所以:
cd /usr/local/src
wget http://www.cpan.org/src/5.0/perl-5.26.0.tar.gz
tar -zxf perl-5.26.0.tar.gz
./configure.gnu --prefix=/usr/local/related/pel
make && make install


最后安装nginx

cd /usr/local/src

wget http://nginx.org/download/nginx-1.12.1.tar.gz

tar -zxvf nginx-1.12.1.tar.gz

cd nginx-1.12.1

./configure--sbin-path=/usr/local/nginx/nginx\   --设置nginx的运行目录

--conf-path=/usr/local/nginx/nginx.conf\              --设置nginx的配置目录

--pid-path=/usr/local/nginx/nginx.pid\                  --设置nginx的pid

--with-http_v2_module\                                     --开启http2支持

--with-http_ssl_module\                                        --开启ssl模块

--with-pcre=/usr/local/src/pcre-8.41\                  --pcre的源码包所在路径  --可用新版本

--with-zlib=/usr/local/src/zlib-1.2.8\                      --zlib的源码包所在路径  --可用新版本

--with-openssl=/usr/local/src/openssl-1.0.1t    --openssl的源码包所在路径  --可用新版本

./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-http_v2_module --with-pcre=/usr/local/src/pcre-8.42 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/src/openssl-1.0.2o

make

make install

至此,大功告成

猜你喜欢

转载自www.cnblogs.com/xiehuazhen/p/10142031.html