ubuntu nginx源代码安装

下载源代码

http://nginx.org/en/download.html

tar -xvf nginx-.tar.gz
./configure

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.

安装pcre

sudo apt install libpcre3 libpcre3-dev

继续安装nginx

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib= option.

安装zlib

下载地址:http://www.zlib.net/

 tar -xvf zlib-.tar.gz 
 cd zlib-/
./configure
make
make install

继续configure nginx,编译没有问题了

make && make install

源码的安装路径为 /usr/local/nginx/sbin/nginx 而采用apt安装的路径为/usr/sbin/nginx
apt安装的版本为1.10.3 源代码安装的版本是1.15.10
以下为了实现平移

  1. 结束nginx进程
  2. 将/usr/sbin/nginx备份一下 并创建软链接
mv /usr/sbin/nginx /usr/sbin/nginx_old
ln -s /usr/local/nginx/sbin/nginx  /usr/sbin/nginx

再次启动时:

Failed to start A high performance web server and a reverse proxy server.

重新编译:

./configure --with-http_ssl_module

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl= option.

安装ssl library

源码:https://www.openssl.org/source/

  $ ./config
  $ make
  $ make test
  $ make install

nginx:

./configure --with-http_ssl_module --with-openssl=
make && make install

运行:

nginx: [emerg] unknown directive "stream" in /etc/nginx/nginx.conf:78

nginx重新配置

./configure --with-http_ssl_module --with-openssl= --with-stream
make && make install

你可能感兴趣的:(ubuntu nginx源代码安装)