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

企业级Nginx安装部署

企业级Nginx安装部署

1. Nginx 安装方式

  • 编译安装:使用源码,根据企业业务需求,需要什么功能,编译时添加什么模块,但是安装过程较为繁琐
  • 自动化安装:配置好安装源,直接通过自动化工具安装即可
  • 二进制安装:解压即用,直接下载已经编译好的可执行文件

2. Nginx 编译安装

2.1 下载源码包

https://nginx.org/en/download.html

本文使用 nginx-1.26.3.tar.gz

2.2 编译安装

# 安装依赖包
$ sudo yum install -y gcc pcre pcre-devel openssl openssl-devel zlib zlib-devel$ tar -zxvf nginx-1.26.3.tar.gz
$ cd nginx-1.26.3# 编译
$ ./configure \--prefix=/usr/local/nginx \ # 设置 nginx 安装目录--sbin-path=/bin/ \ # nginx 命令存放目录--user=nginx \ # 设置运行 nginx 服务的用户--group=nginx \ # 设置运行 nginx 服务的组--with-http_ssl_module \ # 使用 --with 添加了 6 个模块--with-http_stub_status_module \--with-http_gzip_static_module \--with-http_v2_module \--with-stream \--with-stream_ssl_module$ make
$ sudo make install# 测试
$ nginx -v
nginx version: nginx/1.26.3
$ nginx -V
nginx version: nginx/1.26.3
built by gcc 11.4.1 20231218 (Red Hat 11.4.1-3) (GCC) 
built with OpenSSL 3.5.1 1 Jul 2025
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --sbin-path=/bin/ --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_v2_module --with-stream --with-stream_ssl_module# 创建 nginx 用户
$ sudo useradd nginx -M -s /sbin/nologin# 启动 Nginx 服务
$ nginx# 验证
$ netstat -lntup | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      28787/nginx: master$ curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p>
</body>
</html>

2.3 编译常见报错

# 报错 1 ./configure: error:C compiler cc is not found 
# 报错 1 解决办法
$ sudo yum install -y gcc# 报错 2 ./configure: error: the HTTP rewrite module requires the PCRE library.
# You can either disable the module by using --without-http_rewrite_module option, 
# or install the PCRE library into the system, 
# or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option. 
# 报错 2 解决办法
$ sudo yum install -y pcre pcre-devel# 报错 3 ./configure: error: SSL modules require the OpenSSL library.
# You can either do not enable the modules, or install the OpenSSL libraryinto the system,
# or build the OpenSSL library statically from the sourcewith nginx by using --with-openssl=<path> option.
# 报错 3 解决办法
$ sudo yum install -y openssl openssl-devel# 报错 4 ./configure: error: the HTTP gzip module requires the zlib library.
# You can either disable the module by using --without-http_gzip_module
# option, or install the zlib library into the system, or build the zlib library
# statically from the source with nginx by using --with-zlib=<path> option.
# 报错 4 解决办法
$ sudo yum install -y zlib zlib-devel

3. YUM 安装 Nginx

https://nginx.org/en/linux_packages.html#RHEL

$ sudo yum install yum-utils$ sudo tee /etc/yum.repos.d/nginx.repo > /dev/null << 'EOF'
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF# 如果只想安装稳定版本,则不要执行这条命令
$ sudo yum-config-manager --enable nginx-mainline# 关闭 mainline 源
$ sudo yum-config-manager --disable nginx-mainline$ sudo yum install nginx -y$ systemctl enable nginx --now$ sudo ln -s /usr/sbin/nginx /usr/bin/nginx
http://www.rkmt.cn/news/30845.html

相关文章:

  • 2025 年 10 月门窗十大品牌综合实力权威推荐榜单,精准检测与稳定性能兼具的行业优选解析
  • 2025 年 10 月门窗十大品牌综合实力权威推荐榜单,聚焦高端定制需求与全案交付能力
  • 力扣 第473场周赛(A~D)
  • Java学习与工作汇报总结
  • Alibaba Cloud Linux 4 镜像备份到自己的 OSS 中,并同时使用该镜像部署
  • Function Calling
  • 20232302 2025-2026-1《网络与系统攻防技术》实验三实验报告
  • 2025 年 10 月门窗十大品牌综合实力权威推荐榜单,产能、专利、环保三维数据透视
  • 2025年10月膜结构厂家推荐榜:双资质企业对比评测 ,
  • 2025 年 10 月蒸汽发生器厂家最新推荐,聚焦高端定制需求与全案交付能力
  • 2025 年 10 月蒸汽发生器厂家最新推荐,精准检测与稳定性能深度解析
  • 2025年10月敏感肌产品推荐榜:淡斑修护面霜排名一览
  • LLM-提示词(二)
  • Windows下编译ffmpeg(MinGW+MSYS2)参考链接
  • 2025 年 10 月贵州旅游旅行社最新推荐,聚焦高端定制需求与全案交付能力
  • 2025 年 10 月贵州旅游旅行社最新推荐,实力品牌深度解析采购无忧之选!
  • 存储系统
  • 102302122许志安作业1
  • ARC201B Binary Knapsack
  • LDC
  • 完整教程:由JoyAgent观察AI Agent 发展
  • Spark计算引擎
  • 173天隧道技术篇防火墙组策略ICMPDNSSMB协议出网判断C2上线解决方案
  • 实用指南:3DGS 如何理解它?
  • 面试总被追问k8s调度器工作原理, 收藏 == 学废
  • 题解:十二重计数法
  • 2025 年 10 月厨房排烟、厨房排烟罩、厨房排烟系统厂家最新推荐,资质、案例、售后三维测评与选购指南
  • # Ubuntu 根目录空间扩展操作手册(基于 RAID 关联磁盘 /dev/sdb2)
  • Perplexity Comet AI浏览器「等待网络链接」解决方案
  • 新地球