当前位置: 首页 > 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.hskmm.com/?act=detail&tid=39411

相关文章:

  • 2025 年 10 月门窗十大品牌综合实力权威推荐榜单,聚焦产能、专利与环保的实力品牌深度解析
  • 以“听”为基,以“做”为翼
  • 解码Linux文件IO之中文字库原理与应用
  • 企业级Web应用及Nginx介绍
  • 2025 年 10 月门窗十大品牌综合实力权威推荐榜单,精准检测与稳定性能兼具的行业优选解析
  • 使用EasyBlogImageForTypora将Typora上传图床改为博客园——2025/10/26最新
  • 博客1
  • 2025 年 10 月门窗十大品牌综合实力权威推荐榜单,技术实力与市场口碑深度解析
  • HarfBuzz概览汇报总结
  • 题解:P5853 [USACO19DEC] Tree Depth P
  • 2025 年 10 月门窗十大品牌综合实力权威推荐榜单,聚焦高端定制需求与全案交付能力
  • idea或pycharm工具报python packaging tools not found. install packaging tools
  • 吃不东了
  • Alibaba Cloud Linux 4 镜像备份到自己的 OSS 中,并同时使用该镜像部署
  • Java学习与工作汇报总结
  • Function Calling
  • 《代码大全》读后感(1)
  • [K230学习笔记 02] I2C - Ze
  • day01 AI入门讲解
  • 实验作业3
  • ? #5
  • GitLab:代码管理 - 教程
  • 20232302 2025-2026-1《网络与系统攻防技术》实验三实验报告
  • MCP Router使用学习
  • fvm Flutter多版本管理安装与常用指令
  • 人生八要(摘抄)
  • 20232322 2025-2026-1 《网络与系统攻防技术》实验三实验报告
  • 2025年内窥镜电缆线厂家权威推荐榜:B超线内窥镜电缆线,专业医疗线缆制造与定制化解决方案精选
  • 网络流题单
  • 2025年盐趣科研教育深度解析:从录取数据看科研背景如何撬动名校门槛