0.安装Nginx依赖包

yum install -y pcre-devel zlib-devel openssl-devel wget gcc tree vim

1.从Nginx官网下载并解压源码包

wget https://nginx.org/download/nginx-1.16.1.tar.gz
tar -zxvf nginx-1.16.1.tar.gz

2.Nginx编译前配置

cd nginx-1.16.1
./configure --prefix=/usr/local/nginx --with-http_ssl_module

--prefix:配置configure脚本,软件的安装位置

3.进行安装编译

make && make install

4.检查安装情况

进入安装目录进行检查

cd /usr/local/nginx

#配置文件位置
/usr/local/nginx/conf/nginx.conf

运行nginx

cd sbin
./nginx

5.停止Nginx

#1. 立即停止Nginx服务
/usr/local/nginx/sbin/nginx -s stop
#2.完成当前任务后停止
/usr/local/nginx/sbin/nginx -s quit
#3.杀死Nginx进程
killall nginx

6.Nginx添加到环境变量

使用软连接将nginx链接到/usr/local/sbin

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
ll /usr/local/sbin/ | grep "nginx"
#1.显示当前环境变量`PATH`
echo $PATH
#2.编辑`.bash_profile`文件
vim ~/.bashrc
#3.在`.bash_profile`文件末尾加入以下内容
export PATH=$PATH:/usr/local/nginx/sbin
#4.立即生效
source ~/.bashrc