官网下载
https://nginx.org/en/download.html
解压
tar -zxvf nginx-1.24.0.tar.gz
安装依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
指定目录安装
-
进入到解压目录nginx-1.24.0
-
配置prefix
./configure --prefix=/data/nginx
- 安装
make && make install
配置开机自动启动
- 进入系统服务目录编写服务
cd /etc/systemd/system/
vi nginx.service
#/bin/bash
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/data/nginx/sbin/nginx -c /data/nginx/conf/nginx.conf
ExecReload=/data/nginx/sbin/nginx -s reload
ExecStop=/data/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
- 授权
chmod 777 nginx.service
- 设置开机启动
systemctl enable nginx.service
- 服务命令
# 启动nginx
systemctl start nginx.service
# 停止nginx
systemctl stop nginx.service
# 重启nginx
systemctl restart nginx.service
# 查看nginx运行状态
systemctl status nginx.service
注意: 原先通过nginx目录启动的nginx进程需要先结束掉才能使用服务启动和结束