Ubuntu下安装nginx的步骤分享

2020-02-03 10:50:41王振洲
1)、下载
  sudo wget http://nginx.org/download/nginx-1.2.2.tar.gz

2)、解压
  sudo tar -xzvf nginx-1.2.2.tar.gz

3)、进入相关目录进行以下操作

复制代码
./configure
make
sudo make install  

如果你运气好的话,一切ok,不过...........哈哈。Ubuntu默认的策略是什么库都不装,依赖的库都需要自已手工安装搞定。 一般都会出错的,那么我们来看看可能出现的问题。

4)、常见问题解决办法
  缺少pcre library
./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=<path> option.   
解决方法:下载安装pcre-8.31解决问题,解压后对pcre进行如下操作

复制代码
sudo wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gz
sudo tar -xzvf pcre-8.31.tar.gz
cd /usr/local/src/pcre-8.31
./configure
make
sudo make install  

运气好一次通过,运气不好,make pcre时会出错
缺少gcc-c++和libtool,也就是c++编译包

复制代码
libtool: compile: unrecognized option `-DHAVE_CONFIG_H'
libtool: compile: Try `libtool --help' for more information.
make[1]: *** [pcrecpp.lo] Error 1
make[1]: Leaving directory `/usr/local/src//pcre-8.31'
make: *** [all] Error 2root@wolfdog-virtual-machine:~/work/pcre-8.12$ libtool -help -DHAVE_CONFIG_H
The program 'libtool' is currently not installed. You can install it by typing:
sudo apt-get install libtool

解决方法:需要先安装libtool和gcc-c++
?sudo apt-get install libtool
sudo apt-get install gcc-c++
  大爷啊~~~这时候可能又会报错啊,坑爹啊~~~
  缺少openssl库

复制代码
./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.

缺少zlib库

复制代码
./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=<path> option.   

解决办法:少什么就安装什么呗。
sudo apt-get install openssl libssl-dev libperl-dev