当前位置: 首页 > news >正文

Nginx稳定版最新1.26.2源码包安装【保姆级教学】

Nginx安装及配置

开源Nginx官网地址(https://nginx.org)

Nginx源码包下载地址(https://nginx.org/en/download.html)

  1. Mainline version 主线版本
  2. Stable version 稳定版本
  3. Legacy versions 陈旧版本
  • 下载Nginx源码文件

    curl -O https://nginx.org/download/nginx-1.26.2.tar.gz

源码安装
  • 安装依赖

在安装操作系统的安装软件配置部分,建议选择“Server with GUI”,并选择“Development Tools”和“Compatibility Libraries”两项附加软件。确保gcc、libgcc、gcc-c++等编译器已经正确安装。

在安装Nginx之前,需要安装一些Nginx的依赖程序,Nginx的主要依赖程序有zlib、pcre、openssl三个,其中,zlib用于支持gzip模块,pcre用于支持rewrite模块,openssl用于支持ssl功能,为了简单快捷,推荐通过yum安装zlib、pcre、openssl软件包。

安装方式如下:

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

# 如果安装的操作系统为最小化,那么可以使用yum安装一下软件包组
# 查看软件包组列表
yum grouplist
# 下载“Development Tools”和“Compatibility Libraries”两项附加软件
yum -y groupinstall "Development Tools"
yum -y groupinstall "Compatibility Libraries"

编译安装完成后,可以使用nginx命令来查看编译安装的配置规则

# -v :显示版本并退出
# -V :显示版本和配置选项然后退出
/usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.26.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --pid-path=/usr/local/nginx/logs/nginx.pid --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre
  • 编写启动脚本

    cat < /etc/systemd/system/nginx.service
    [Unit]
    Description=The nginx HTTP and reverse proxy server
    After=network.target remote-fs.target nss-lookup.target

    [Service]
    Type=forking
    PIDFile=/usr/local/nginx/logs/nginx.pid
    ExecStartPre=/usr/bin/rm -f /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
    KillSignal=SIGQUIT
    TimeoutStopSec=5
    KillMode=process
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target
    EOF

  • 重新加载systemd管理器配置

    systemctl daemon-reload

  • 管理Nginx服务

当我们配置好启动文件之后,就可以通过systemctl来管理nginx服务了。

# 重载nginx服务
systemctl reload nginx
# 启动nginx服务
systemctl start nginx
# 关闭nginx服务
systemctl stop nginx
# 设置nginx服务开机自启动
systemctl enable nginx
# 查看nginx服务运行状态
systemctl status nginx
# 查看nginx服务是否设置自启动
systemctl is-enabled nginx

相关文章:

  • L0G3000 Git 基础知识
  • 栈,优先级队列,map,set
  • Python——生成AIGC图像
  • 使用 AIStor 和 OpenSearch 增强搜索功能
  • java项目之学术成果管理系统源码(ssm+前端+mysql)
  • 基于契约理论的竞争性组织数据共享安全激励机制matlab模拟与仿真
  • 使用Python结合`stable-baselines3`库(包含PPO和TD3算法)以及`gym`库来实现分层强化学习的示例代码
  • 0.1 量海航行:量化因子列表汇总(持续更新)
  • 项目设置内网 IP 访问实现方案
  • leecode 刷题感悟-- 哈希表
  • Kafka Connect 功能介绍
  • 本地部署 DeepSeek + Dify,构建自己的AI能力
  • 为AI聊天工具添加一个知识系统 之113 详细设计之54 Chance:偶然和适配 之2
  • 云计算如何解决延迟问题?
  • 数字内容体验驱动用户参与度提升的关键路径
  • 日语学习-日语知识点小记-构建基础-JLPT-N4N5阶段(10): になります :表示从一种状态转变为另一种状态,“变得……”“成为……”
  • Spark提交任务
  • Java中的常用类 --String
  • 备战蓝桥杯 -牛客
  • 全志A133 android10 适配SLM770A 4G模块
  • 东道设计学院/seo是什么品牌
  • vs做b s网站/促销活动推广方案
  • 长春模板建站公司/成都网络营销公司
  • 深圳品牌网站建设公司排名/友情链接网站大全
  • 安庆市住房和建设厅网站首页/市场运营和市场营销的区别
  • 淘宝网站是怎么做的吗/百度高级搜索页面