Centos7 安装 Nginx
Centos7 安装 Nginx
step1:CentOS 7 更换软件仓库
以阿里云的软件仓库 https://developer.aliyun.com/mirror/为例
yum repolist
打开阿里云的镜像网站https://developer.aliyun.com/mirror/
复制命令到终端上执行
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
step2:安装环境
我这里是Centos7.0作为安装环境,除此之外还要安装gcc,pcre等软件,都是一个命令就安装的。
gcc
安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc。
yum install gcc-c++
PCRE
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
yum install -y pcre pcre-devel
注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。
zlib
zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
yum install -y zlib zlib-devel
openssl
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。
nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
yum install -y openssl openssl-devel
官网下载nginx-1.9.9.tar.gz安装包
wget http://nginx.org/download/nginx-1.9.9.tar.gz
解压
tar -zxvf nginx-1.9.9.tar.gz
查找安装位置
whereis nginx
step3:编译&运行
编译
./configure && make && make install
运行
cd /usr/local/nginx/sbin
./nginx
检查进程
ps aux|grep nginx
root 6034 0.0 0.0 24896 772 ? Ss 12:04 0:00 nginx: master process ./nginx
nobody 6035 0.0 0.0 27392 1520 ? S 12:04 0:00 nginx: worker process
root 6045 0.0 0.0 112824 988 pts/1 S+ 12:04 0:00 grep --color=auto nginx
step4:关闭防火墙测试
systemctl stop firewalld