linux安装nginx,配置系统文件,配置systemctl命令,亲测可用,

先安装gcc-c++编译器

java 复制代码
yum install gcc-c++
java 复制代码
yum install -y openssl openssl-devel

安装pcre包

java 复制代码
yum install -y pcre pcre-devel

安装zlib包

java 复制代码
yum install -y zlib zlib-devel

在/usr/local/创建nginx文件

java 复制代码
mkdir /usr/local/nginx

进入nginx目录

java 复制代码
cd /use/local/nginx

下载nginx安装包

java 复制代码
wget https://nginx.org/download/nginx-1.19.9.tar.gz

注:如果没有wget命令,就安装命令

java 复制代码
yum install wget

解压安装包

java 复制代码
tar -zxvf nginx-1.19.9.tar.gz
java 复制代码
cd nginx-1.19.9

执行以下三个命令

java 复制代码
./configure
java 复制代码
make
java 复制代码
make install

添加到系统服务中

java 复制代码
vim /etc/profile

最后加入配置

java 复制代码
export PATH=/usr/local/nginx/sbin:$PATH

重载配置

java 复制代码
source /etc/profile

添加systemctl命令

java 复制代码
vi /usr/lib/systemd/system/nginx.service

添加内容

java 复制代码
[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

重新加载系统服务

java 复制代码
systemctl daemon-reload

启动服务

java 复制代码
systemctl start nginx

停止服务

java 复制代码
systemctl stop nginx

重启服务

java 复制代码
systemctl restart nginx

重载配置文件

java 复制代码
nginx -s reload
相关推荐
IVEN_5 小时前
只会Python皮毛?深入理解这几点,轻松进阶全栈开发
python·全栈
Ray Liang6 小时前
用六边形架构与整洁架构对比是伪命题?
java·python·c#·架构设计
AI攻城狮6 小时前
如何给 AI Agent 做"断舍离":OpenClaw Session 自动清理实践
python
千寻girling6 小时前
一份不可多得的 《 Python 》语言教程
人工智能·后端·python
AI攻城狮9 小时前
用 Playwright 实现博客一键发布到稀土掘金
python·自动化运维
曲幽10 小时前
FastAPI分布式系统实战:拆解分布式系统中常见问题及解决方案
redis·python·fastapi·web·httpx·lock·asyncio
孟健1 天前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析
python
码路飞1 天前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
闲云一鹤1 天前
nginx 快速入门教程 - 写给前端的你
前端·nginx·前端工程化