linux下安装nginx(图文教程)

2019-10-13 18:06:57王振洲

Nginx是一款轻量级的Web 服务器。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好。以下主要介绍linux下安装nginx。

linux系统为Centos 64位

简介

一、Linux安装软件常用方法

1、rpm(或pkg)安装,类似于Windows安装程序,是预编译好的程序。 

    使用的是通用参数编译,配置参数不是最佳
    可控制性不强,比如对程序特定组件的定制性安装
    通常安装包间有复杂依赖关系,操作比较复杂
    安装简单,出错机率低

2、yum(或apt-get)安装,改良版的rpm,自动联网下载安装包,自动管理依赖关系

3、编译安装(方式在各类Linux发行版中差异不大)

    可控性强,config时可根据当前系统环境优化参数,可定制组件及安装参数
    易出错,难度略高

二、Nginx编译安装

1、检查和安装依赖

yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

2、configure

3、make && make install

详细的步骤如下 

第一步:从http://nginx.org/download/上下载相应的版本(或者wget http://nginx.org/download/nginx-1.9.9.tar.gz直接在Linux上用命令下载)

第二步:解压 tar -zxvf nginx-1.9.9.tar.gz

第三步:设置一下配置信息 ./configure --prefix=/usr/local/nginx ,或者不执行此步,直接默认配置

第四步:

make 编译 (make的过程是把各种语言写的源码文件,变成可执行文件和各种库文件)

make install 安装 (make install是把这些编译出来的可执行文件和库文件复制到合适的地方)

在配置信息的时候,也就是在第三步,出现了一下错误:
错误为:./configure: error: the HTTP rewrite module requires the PCRE library.

安装pcre-devel解决问题

yum -y install pcre-devel

还有可能出现:

错误提示:./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.

解决办法:

yum -y install openssl openssl-devel

安装后在linux下启动和关闭nginx:

启动操作

/usr/local/nginx/sbin/nginx (/usr/local/nginx/sbin/nginx -t 查看配置信息是否正确)

停止操作

停止操作是通过向nginx进程发送信号(什么是信号请参阅linux文 章)来进行的