一:环境
centos7
二:安装准备
要先确保系统安装了g++、gcc、openssl-devel、pcre-devel和zlib-devel软件
三:安装依赖
[root@zyyy]# yum install gcc-c++
[root@zyyy]# yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
//如果已安装,则remove掉
[root@zyyy]# yum remove nginx
四:下载nginx
[root@zyyy]# wget https://nginx.org/download/nginx-1.16.0.tar.gz
五:安装nginx
1:解压与编译
//解压
[root@zyyy nginx]# tar -zxvf nginx-1.11.3.tar.gz
//一般都会放到 /usr/local 目录下边去
//移动到 /usr/local/nginx-1.11.3目录下
[root@zyyy nginx]# mv nginx-1.11.3 /usr/local/nginx-1.11.3
//在user/local下创建一个nginx的目录
[root@zyyy local]# mkdir nginx
//编译安装
[root@zyyy nginx-1.16.0]# ./configure --prefix=/usr/local/nginx
[root@zyyy nginx-1.16.0]# make
[root@zyyy nginx-1.16.0]# make install
此时nginx已经安装成功

2:启动,停止,重启
进入sbin目录使用命令

//启动代码格式:nginx安装目录地址 -c nginx配置文件地址
[root@zyyy sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
//停止
//先查看进程
[root@zyyy sbin]# ps -ef|grep nginx

//然后再杀死进程
[root@zyyy sbin]# kill -term 18848

//重启,sbin目录下输入./nginx -s reload即可
[root@zyyy sbin]# ./nginx -s reload
3:验证nginx配置文件是否正确
进入sbin目录下使用,出现下图表示正确
[root@zyyy sbin]# ./nginx -t

[root@zyyy sbin]# /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
各种命令 nginx -h #帮助
nginx -v #显示版本
nginx -V #显示版本和配置信息
nginx -t #测试配置
nginx -q #测试配置时,只输出错误信息
nginx -s stop #停止服务器
nginx -s reload #重新加载配置