一、环境介绍
1.Centos版本:Centos7-X86_64-Eeverything2009
2.Nginx版本:nginx-1.18.0
二、部署Nginx思路
1.安装依赖
2.下载Nginx
3.Configure
4.编译
5.安装
三、部署Nginx详细步骤
3.1 准备工作
1.关闭防火墙
#临时关闭防火墙
[root@test ~]# systemctl stop firewalld
#永久关闭防火墙
[root@test ~]# systemctl disable firewalld
2.关闭selinux
#临时关闭selinux
[root@test ~]# setenforce 0
#永久关闭selinux
[root@test ~]# vim /etc/selinux/config
SELINUX=disabled
3.安装依赖
[root@test ~]# yum install gcc zlib zlib-devel pcre-devel -y
3.2 开始部署
1.下载nginx
[root@test ~]# cd /opt/
[root@test opt]# wget https://nginx.org/download/nginx-1.18.0.tar.gz
2.解压安装包
[root@test opt]# tar xf nginx-1.18.0.tar.gz
3.configure配置,其中--prefix=/opt/nginx指定安装目录,默认是装在/usr/local/
[root@test opt]# cd nginx-1.18.0/
[root@test nginx-1.18.0]# ./configure --prefix=/opt/nginx
4.编译
[root@test nginx-1.18.0]# make
5.安装
[root@test nginx-1.18.0]# make install
6.至此安装完成
四 、常用操作
1.启动nginx
[root@test nginx]# ./sbin/nginx
2.检查主配置文件语法是否正确
[root@test nginx]# ./sbin/nginx -t
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful
3.快速关机
[root@test nginx]# ./sbin/nginx -s stop
4.优雅关机,停止Nginx进程,等待工作进程完成当前的请求服务,再关机
[root@test nginx]# ./sbin/nginx -s quit
5.重新加载配置文件
[root@test nginx]# ./sbin/nginx -s reload