惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - dirgo

在Oracle中,授予用户角色和权限 Linux下查看当前哪些端口在监听状态,哪些端口在连接状态 mobaxterm常用配置 Windows下udp工具 Oracle表空间用户授权创建dblink等操作 用nmap扫描找出某个网段下空闲的ip脚本 Oracle 19c 常用运维 SQL Linux下设置CDB/PDB 环境的Oracle19c开机启动 Oracle是 CDB/PDB 环境下,让PDB在数据库启动后自动打开 怎样禁止dbeaver点击导航中数据库自动切换sql编辑器所属的数据库 Oracle 19c占内存高的解决方法 sudo -i -u zhangsan 与su - zhangsan区别,在现代 Linux 系统中,推荐使用 sudo 进行权限切换 Linux 的目录结构英文全称(及可能的命名背景)和更详细的说明 利用 Logback 的热加载特性,安全的迁移日志,改变日志保存路径 Linux中查询进程内存占用 iotDB调整内存占用及注意事项 Eclipse Milo 处理PLC"字(Word)"类型,最直接和正确的做法是使用其内置的 UShort 类型 centos7.9安装minio RELEASE.2025-04-22T22-12-26Z linux(centos7.9)编译安装redis7.2.4 UFW 防火墙常用命令速查表
centos7.9编译安装nginx 1.28.1
dirgo · 2025-12-26 · via 博客园 - dirgo

为了在CentOS 7.9上精确安装Nginx 1.28.1,最可靠的方法是编译安装。因为通过系统包管理器(yum)默认安装的通常是较旧的稳定版,无法指定具体的次要版本。

编译安装步骤概览

整个过程可以分为以下四个主要阶段,你需要以 root 权限或在命令前添加 sudo 来执行:

1. 准备环境 安装编译器、依赖库 yum -y install gcc make pcre-devel zlib-devel openssl-devel2. 编译与安装 下载源码、配置、编译、安装 ./configure --prefix=/usr/local/nginx
make && make install3. 安装后配置 环境变量、管理命令、防火墙 echo 'export PATH=/usr/local/nginx/sbin:$PATH' >> ~/.bashrc
firewall-cmd --permanent --add-service=http4. 验证与管理 启动服务,测试访问 nginx
curl -I http://localhost
阶段 主要任务 关键指令/操作

详细步骤说明

下面是每个阶段的详细操作和说明:

第一步:安装编译环境
在编译开始前,需要安装必要的工具和开发库。

yum -y install gcc make pcre-devel zlib-devel openssl-devel

第二步:下载与编译Nginx 1.28.1

  1. 下载源码包:前往 Nginx官方下载页面 找到 nginx-1.28.1.tar.gz 的链接,然后下载到服务器。这里以 /usr/local/src 目录为例:
    cd /usr/local/src
    wget https://nginx.org/download/nginx-1.28.1.tar.gz
    
  2. 解压并进入目录
    tar -zxvf nginx-1.28.1.tar.gz
    cd nginx-1.28.1
    
  3. 配置编译选项:运行 ./configure 脚本。下面的命令指定了安装路径并启用了一些常用模块(如SSL、HTTP/2)。你可以根据需求调整,使用 ./configure --help 查看所有选项。
    ./configure --prefix=/usr/local/nginx \
    --with-http_ssl_module \
    --with-http_v2_module \
    --with-http_realip_module \
    --with-stream \
    --with-stream_ssl_module \
    --with-http_gzip_static_module \
    --with-http_secure_link_module \
    --with-http_slice_module \
    --with-threads \
    --with-file-aio \
    --with-pcre
    

http_ssl_module, http_v2_module: 用于HTTPS与HTTP/2。

stream, stream_ssl_module: 用于TCP/UDP代理(如未来可能的数据库负载均衡)。

http_gzip_static_module: 用于Vue3等静态文件预压缩。

http_secure_link_module, http_slice_module: 用于MinIO安全链接和文件分片。

threads, file-aio: 用于性能优化。

pcre: 用于正则表达式支持。

  1. 编译并安装
    make
    make install
    

第三步:安装后的配置与管理

  1. 为了方便使用,可以将Nginx的可执行文件路径加入系统环境变量:
    echo 'export PATH=/usr/local/nginx/sbin:$PATH' >> ~/.bashrc
    source ~/.bashrc
    
  2. 配置防火墙,允许HTTP/HTTPS流量:
    firewall-cmd --permanent --add-service=http
    firewall-cmd --permanent --add-service=https
    firewall-cmd --reload
    
  3. 创建系统服务(推荐):为了方便使用 systemctl 管理,可以创建一个服务文件。
    vi /etc/systemd/system/nginx.service
    
    将以下内容粘贴进去:
    [Unit]
    Description=nginx - high performance web server
    After=network.target
    
    [Service]
    Type=forking
    PIDFile=/usr/local/nginx/logs/nginx.pid
    ExecStartPre=/usr/local/nginx/sbin/nginx -t
    ExecStart=/usr/local/nginx/sbin/nginx
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s TERM $MAINPID
    
    [Install]
    WantedBy=multi-user.target
    
    然后启用并启动服务:
    systemctl daemon-reload
    systemctl enable nginx  # 设置开机自启
    systemctl start nginx   # 启动Nginx
    

第四步:验证与基本管理

  • 验证安装:执行 nginx -v 应显示版本 1.28.1。访问服务器IP,应能看到Nginx欢迎页。
  • 常用管理命令
    • 启动:systemctl start nginx
    • 停止:systemctl stop nginx
    • 重启:systemctl restart nginx
    • 重新加载配置(不中断服务):systemctl reload nginx
    • 测试配置文件语法:nginx -t

重要目录与后续配置

  • 配置目录:主配置文件位于 /usr/local/nginx/conf/nginx.conf。网站配置文件通常放在同目录下或 /etc/nginx/conf.d/
  • 网站根目录:默认在 /usr/local/nginx/html
  • 日志目录:位于 /usr/local/nginx/logs/

注:如果已安装旧版Nginx,请先通过 yum remove nginx 卸载,或确保编译安装路径与旧版不同,避免冲突。