基于Centos7的Nginx源码安装

目录

1、准备安装环境

2、获取tar包:

3、解压创建软链接

4、创建用户和组

5、执行安装

6、创建服务脚本

7、开启nginx:​编辑​编辑


1、准备安装环境

bash 复制代码
yum insatall -y make gcc gcc-c++ pcre-devel
#pcre-devel -- pcre库
#安装openssl-devel
yum install -y openssl-devel

2、获取tar包:

Index of /download/

3、解压创建软链接

bash 复制代码
tar -xf nginx-1.22.0.tar.gz -C /usr/local/
ln -s /usr/local/nginx-1.22.0/ /usr/local/nginx

4、创建用户和组

bash 复制代码
groupadd -r nginx
useradd nginx -u 996 -r -g 996 -c "nginx user"

5、执行安装

bash 复制代码
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

make && make

6、创建服务脚本

bash 复制代码
#vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/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=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

#systemctl daemon-reload

7、开启nginx:

相关推荐
std78793 分钟前
核电站里,机器人当起“侦察兵”
运维·安全·机器人
顾安r7 分钟前
11.14 脚本网页 青蛙过河
服务器·前端·python·游戏·html
HIT_Weston9 分钟前
30、【Ubuntu】【远程开发】内网穿透:反向隧道建立(二)
linux·运维·ubuntu
Percep_gan19 分钟前
在Linux中安装字体
linux·运维·服务器
不爱吃糖的程序媛32 分钟前
Electron 智能文件分析器开发实战适配鸿蒙
前端·javascript·electron
ZStack开发者社区36 分钟前
VMware替代 | ZStack ZSphere虚拟化平台金融级高可用能力解析
服务器·jvm·金融·云计算
q***494536 分钟前
如何安装配置Goland并使用固定公网地址SSH远程连接本地服务器
运维·服务器·ssh
Doro再努力37 分钟前
2025_11_14洛谷【入门1】数据结构刷题小结
前端·数据结构·算法
Stella25211 小时前
【Jenkins/Termius/集群概念】
运维·servlet·jenkins
清清&1 小时前
【Linux】冯诺依曼体系结构和操作系统的理解
linux·运维·服务器