一、查看Centos版本
本文使用的机器为Centos8,查看centos版本的命令如下:
cat /etc/redhat-release
二、安装依赖
yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel
二、下载Nginx
本文使用是Nginx-1.27.0版本,文件后缀为.tar.gz,下载NVM的链接如下:
三、安装
- 将下载的NVM文件上传到
/opt安装目录,然后解压,解压后的文件夹名字为:nginx-1.27.0:
tar -zxvf nginx-1.27.0.tar.gz
- 进入Nginx目录,配置SSL:
cd nginx-1.27.0
# 不需要SSL认证
./configure --prefix=/opt/nginx
# 需要SSL认证
./configure --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module
- 编译安装:
make
make install
- 启动Nginx:
/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
- 重启Nginx:
/opt/nginx/sbin/nginx -s reload
四、开机自动启动
- 进入到
/lib/systemd/system目录:
cd /lib/systemd/system
vim创建nginx.service文件:
[Unit]
Description=nginx service
After=network.target
[Service]
Type=forking
ExecStart=/opt/nginx/sbin/nginx
ExecReload=/opt/nginx/sbin/nginx -s reload
ExecStop=/opt/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
- 加入开机自启动:
systemctl enable nginx
- 关闭开机自启动:
systemctl disable nginx
- 启动Nginx:
systemctl start nginx.service
- 停止Nginx:
systemctl stop nginx.service