CentOS7 安装1.14.x版本的Nginx
# CentOS7 安装1.14.x版本的Nginx
1. 下载Nginx安装包
Nginx的官网下载地址:http://nginx.org/en/download.html

Nginx官方提供了三个类型的版本
- Mainline version : Mainline 是 Nginx 目前主力在做的版本,可以说是开发版
- Stable version:最新稳定版,生产环境上建议使用的版本
- Legacy versions:历史版本中的稳定版
这里,我们选择 nginx-1.14.2 版本。点击之后即可下载。
2.编译安装前所需要的准备
-
需要安装gcc的环境。
yum install gcc-c++ -
PCRE库
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。yum install -y pcre pcre-devel -
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
3. 安装和配置Nginx
-
把nginx的源码包上传到linux系统中
-
解压缩到/usr/local目录下
tar -zxf nginx-1.14.2.tar.gz -C /usr/local/ -
进入解压后的nginx目录
cd /usr/local/nginx-1.14.2/ -
执行configure命令
./configure![1548656182944]()
执行完毕之后,会显示nginx的配置信息
如 配置概述,使用了 PCRE 库
nginx的路径 /usr/local/nginx
等等
-
编译和安装
make && make install -
启动
进入nginx的bin目录
cd /usr/local/nignx/sbin启动nginx
./nginx查看nginx是否启动
ps -ef | grep nginx![1548656513731]()
其中的作用
-
nginx :master 主进程,监控和管理nginx
-
nginx :worker 工作进程,处理用户请求
关闭Nginx
./nginx -s stop重启nginx
./nginx -s reload -
-
关闭防火墙
CentOs 7默认使用的是
firewall作为防火墙- 查看防火墙状态
firewall-cmd --state- 停止firewall
systemctl stop firewalld.service- 禁止firewall开机启动
systemctl disable firewalld.service
访问 Nginx 服务器

访问成功。



浙公网安备 33010602011771号