官网地址 https://nginx.org/
安装
-
上传安装包到linux中
image.png - 解压
tar -zxvf nginx-1.23.1.tar.gz
## 进入目录
cd nginx-1.23.1
- 安装缺少的依赖
./configure
出现错误,安装对应的依赖
image.png
yum install -y gcc
image.png
yum install -y pcre pcre-devel
image.png
yum install -y zlib zlib-devel
- 执行安装命令
./configure
make
make install
- 关闭防火墙
## 关闭防火墙
systemctl stop firewalld.service
## 禁用防火墙
systemctl disable firewalld.service
- 进入安装目录
cd /usr/local/nginx/
cd sbin/
# 启动
./nginx
## 重新加载配置
./nginx -s reload
## 退出钱完成已接收的请求
./nginx -s quit
## 快速停止
./nginx -s stop
- 安装成服务
vim /usr/lib/systemd/system/nginx.service
内容:
[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重新加载系统服务
systemctl daemon-reload
## 关闭nginx
./nginx -s stop
使用系统服务启动nginx
systemctl start nginx
## 查看状态
systemctl status nginx
## 设置开启启动
systemctl enable nginx
- 重启linux 查看是否开机启动
## 重启
reboot