Ngnix的安装启动详解

ububtu平台编译环境可以使用以下指令

apt-get install build-essential
apt-get install libtool

centos平台编译环境使用如下指令

安装make:

yum -y install gcc automake autoconf libtool make

安装g++:

yum install gcc gcc-c++

下面正式开始

一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。

  • 本人实际操作过程中均为yum安装。

  • 1.选定源码目录
    可以是任何目录,本文选定的是/usr/local/src

cd /usr/local/src
cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz 
tar -zxvf pcre-8.37.tar.gz
cd pcre-8.34
./configure
make
make install

cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
tar -zxvf pcre-8.37.tar.gz
cd pcre-8.34
./configure
make
make install

当然也可以yum安装

cd /usr/local/src
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
make install

cd /usr/local/src
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
make install
  • 4.安装ssl(某些vps默认没装ssl)
cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
tar -zxvf openssl-1.0.1t.tar.gz
  • 5.安装nginx

Nginx 一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,下面是把 Nginx 安装到 /usr/local/nginx 目录下的详细步骤:

cd /usr/local/src
wget http://nginx.org/download/nginx-1.4.2.tar.gz
tar -zxvf nginx-1.4.2.tar.gz
cd nginx-1.4.2

./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=/opt/app/openet/oetal1/chenhe/pcre-8.37 \
--with-zlib=/opt/app/openet/oetal1/chenhe/zlib-1.2.8 \
--with-openssl=/opt/app/openet/oetal1/chenhe/openssl-1.0.1t

make
make install

–with-pcre=/usr/src/pcre-8.34 指的是pcre-8.34 的源码路径。
–with-zlib=/usr/src/zlib-1.2.7 指的是zlib-1.2.7 的源码路径。

  • 因yum安装与编译安装不同,包括后期可能有其他升级问题 导致版本不同,./configure时自己指定各参数地址。也可以不指定默认安装。

安装成功后 /usr/local/nginx 目录下如下

Nginx的启动

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

Nginx启动后验证

在火狐浏览器里输入自己本机的IP地址

安装过程中可能会出现的报错以及解决办法
  • ./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-devel
yum install -y pcre-devel

  • ./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-devel yum install -y zlib-devel

本文为转载后个人整理,参考多个文献,包括自己动手实施过程中的方法与截图。
文献包括:Nginx安装 http://www.nginx.cn/install

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值