基于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:

相关推荐
DoraBigHead5 分钟前
🧭 React 理念:让时间屈服于 UI —— 从同步到可中断的演化之路
前端·javascript·面试
敢敢J的憨憨L27 分钟前
GPTL(General Purpose Timing Library)使用教程
java·服务器·前端·c++·轻量级计时工具库
喝拿铁写前端40 分钟前
Vue 组件通信的两种世界观:`.sync` 与普通 `props` 到底有什么不同?
前端·vue.js·前端框架
美酒没故事°1 小时前
npm源管理器:nrm
前端·npm·npm源
用户22152044278001 小时前
vue3组件间的通讯方式
前端·vue.js
三十_A1 小时前
【实录】使用 patch-package 修复第三方 npm 包中的 Bug
前端·npm·bug
下位子1 小时前
『AI 编程』用 Claude Code 从零到一开发全栈减脂追踪应用
前端·ai编程·claude
tyro曹仓舒1 小时前
Vue单文件组件到底需不需要写name
前端·vue.js
用户47949283569151 小时前
面试官:讲讲2FA 双因素认证原理
前端·后端·安全
乐影1 小时前
TS 模板字符串类型:从基础到进阶的类型编程魔法
前端·typescript