安装环境:腾讯云服务器,CentOs7.5
一、配置安装环境
(1) gcc 安装
安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:
yum install gcc-c++
(2)PCRE pcre-devel 安装
PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令:
yum install -y pcre pcre-devel
(3)zlib 安装
zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。
yum install -y zlib zlib-devel
(4)OpenSSL 安装
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。
yum install -y openssl openssl-devel
二、下载安装包(两种方式,推荐第二种)
下载地址:http://nginx.org/en/download.html
(1)下载指定安装包,使用xftp传输到服务器上
(2)使用wget命令在线下载(在nginx下载链接上右键复制链接地址)
我一般喜欢在系统根目录下新建文件夹software,用来存储网上下载的文件
[root@VM_0_15_centos /]# clear
[root@VM_0_15_centos /]# cd /software/
[root@VM_0_15_centos software]# wget http://nginx.org/download/nginx-1.15.8.tar.gz
--2019-01-10 18:59:43-- http://nginx.org/download/nginx-1.15.8.tar.gz
Resolving nginx.org (nginx.org)... 95.211.80.227, 62.210.92.35, 2001:1af8:4060:a004:21::e3
Connecting to nginx.org (nginx.org)|95.211.80.227|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1027862 (1004K) [application/octet-stream]
Saving to: ‘nginx-1.15.8.tar.gz’
100%[===============================================================================================================================>] 1,027,862 788KB/s in 1.3s
2019-01-10 18:59:45 (788 KB/s) - ‘nginx-1.15.8.tar.gz’ saved [1027862/1027862]
(三)解压并编译安装
[root@VM_0_15_centos software]# tar -zxvf nginx-1.15.8.tar.gz
[root@VM_0_15_centos software]# cd nginx-1.15.8/
[root@VM_0_15_centos nginx-1.15.8]# ./configure
[root@VM_0_15_centos nginx-1.15.8]# make
[root@VM_0_15_centos nginx-1.15.8]# make install
查看安装路径,默认安装在 /usr/local/nginx,也可以使用以下命令查看
[root@VM_0_15_centos nginx-1.15.8]# whereis nginx
(四)nginx的启动
[root@VM_0_15_centos nginx-1.15.8]# cd /usr/local/nginx/sbin/
[root@VM_0_15_centos sbin]# ./nginx ##启动nginx
[root@VM_0_15_centos sbin]# ./nginx -t ##检验nginx.conf语法的合法性
[root@VM_0_15_centos sbin]# ./nginx -s reload ##重启
[root@VM_0_15_centos sbin]# ./nginx -s stop ##此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。
[root@VM_0_15_centos sbin]# ./nginx -s quit ##此方式停止步骤是待nginx进程处理任务完毕进行停止。
[root@VM_0_15_centos sbin]# ps -ef | grep -i nginx ##查看nginx进程