1、nginx下载
官网下载 http://nginx.org/en/download.html
我使用的版本号是1.9.11
2、准备安装环境
如果不知道安装nginx需要什么环境,解压nginx后,根目录文件是下面这样的。
auto CHANGES.ru configure html Makefile objs src CHANGES conf contrib LICENSE man README |
而configure脚本程序则是用来检查环境和生成编译代码需要的makefile文件,所以可以不断执行configure得知自己缺少了什么环境。
一般缺少的有make(编译工具),gcc,g++,rewrite模块需要的pcre,gzip模块需要的zlib,如果要用ssl的话还需要openssl。
前三者直接安装源上的即可
#可以先通过which命令确认自己时候安装
which gcc
which g++
sudo apt-get install gcc
sudo apt-get install g++
sudo apt-get install make
pcre安装
下载地址 :ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
我这里安装的是pcre-8.36
下载解压后
./configure
make
sudo make install
zlib安装
下载地址:http://www.zlib.net/
我安装的是1.2.8
下载解压后
./configure
make
sudo make install
3、安装nginx
这时候运行nginx目录下的configure已经不报错
这时候进行编译安装
./configure
make
sudo make install
安装后运行
/usr/local/nginx/sbin/nginx
#安装完成#运行nginx后可能会出现 error while loading shared libraries: libpcre.so.1: cannot open sh#ared object file: No such file or directory
#此时添加软链接,其中第一个参数时pcre的安装目录
sudo ln -s /usr/local/lib/libpcre.so.1 /lib
#再次启动nginx
默认端口为80
直接访问ip可验证是否安装成功