Skip to content

Nginx

在这篇文章中

信息

Nginx 是一款高性能的 Web 服务器和反向代理服务器。该解决方案基于 Ubuntu 操作系统提供 Nginx 的快速自动化部署,并支持 SSL/TLS。

主要功能

  • 高性能 - 高效处理大量并发连接。
  • 快速部署 - 安装过程大约需要 5 分钟。
  • 与 Let's Encrypt 集成 - 通过 Certbot 自动配置 SSL 证书,以实现安全的 HTTPS 连接。
  • 模块化架构 - 支持额外模块(GeoIP2、Stream、Mail、Image Filter、XSLT)。
  • 预配置设置 - 预装设置以优化 Web 服务器性能。
  • 支持虚拟主机 - 能够在单个服务器上托管多个网站。
  • 反向代理 - 可用作负载均衡器和缓存代理。

部署功能

ID 软件名称 兼容操作系统 虚拟机 物理机 vGPU GPU 最低CPU(核) 最低内存(GB) 最低硬盘(GB) 自定义域名 是否启用
405 Nginx Ubuntu 22.04 + + + + 1 1 20 订购
  • 安装时间:约 5 分钟;
  • 安装方法:通过 Ansible 进行自动化安装;
  • 所需依赖项:
    • apt(包管理器);
    • systemd;
  • Nginx 版本:1.18.0-6ubuntu14.7;
  • 已安装模块:
    • nginx-core;
    • libnginx-mod-http-geoip2;
    • libnginx-mod-stream;
    • libnginx-mod-stream-geoip2;
    • libnginx-mod-mail;
    • libnginx-mod-http-image-filter;
    • libnginx-mod-http-xslt-filter;
    • python3-certbot-nginx;
  • 主要安装路径:
    • 配置文件:/etc/nginx/
    • 可执行文件:/usr/sbin/nginx
    • 日志:/var/log/nginx/
    • Web 目录:/var/www/html/
    • Systemd 服务:/usr/lib/systemd/system/nginx.service
  • 与 Let's Encrypt 集成:
    • 证书:/etc/letsencrypt/
    • 续期钩子:/etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh
  • 通过 logrotate 自动轮转日志:/etc/logrotate.d/nginx
  • 支持 UFW 防火墙:/etc/ufw/applications.d/nginx

备注

除非另有说明,默认情况下我们从官方存储库安装软件的最新发布版本。

已安装组件的结构

安装完成后,系统中将创建以下目录和文件结构:

配置文件:

/etc/nginx/
├── nginx.conf                          # 主配置文件
├── sites-available/                    # 可用的虚拟主机配置
│   └── nginx71661.hostkey.in.conf
├── sites-enabled/                      # 活动的虚拟主机
│   └── nginx71661.hostkey.in.conf
├── conf.d/                             # 附加配置
└── modules-enabled/                    # 已启用的模块

系统文件:

/etc/init.d/nginx                       # 初始化脚本
/etc/default/nginx                      # 环境变量
/etc/systemd/system/multi-user.target.wants/nginx.service

日志和运行时:

/var/log/nginx/                         # 日志目录
├── access.log                          # 访问日志
└── error.log                           # 错误日志
/run/nginx.pid                          # 进程 PID 文件

Nginx 配置

主配置文件 /etc/nginx/nginx.conf 包含以下设置:

基本参数:

  • 用户:www-data
  • 工作进程:auto
  • 工作连接数:768

HTTP 设置:

  • 启用 sendfile 以优化文件传输
  • 激活 TCP nopush
  • 支持的 MIME 类型来自 /etc/nginx/mime.types

SSL/TLS:

  • 支持的协议:TLSv1、TLSv1.1、TLSv1.2、TLSv1.3
  • 启用服务器密码优先级

日志记录:

  • 访问日志:/var/log/nginx/access.log
  • 错误日志:/var/log/nginx/error.log

压缩:

  • 启用 Gzip 以优化流量

虚拟主机:

  • /etc/nginx/conf.d/*.conf 加载配置
  • 来自 /etc/nginx/sites-enabled/* 的活动站点

重要

修改 Nginx 配置后重启服务前,请务必使用命令 nginx -t 检查语法。

部署 Nginx 后的入门指南

购买订单后,当服务器准备就绪可供使用时,您将收到发送至注册时所用电子邮件地址的通知。该通知将包含 VPS IP 地址以及用于连接的登录凭据。我们的客户通过 服务器控制面板和 APIInvapi 管理设备。

认证数据可在服务器控制面板的 Configuration >> Tags 选项卡或发送的电子邮件中找到:

  • 登录名root
  • 密码:软件部署后服务器准备就绪时,通过电子邮件发送至您的地址。

要使用该服务,请通过 SSH 连接到服务器:

ssh root@<server_ip>

Nginx 安装完成后,会自动启动并准备就绪。 检查 Nginx 服务的状态:

systemctl status nginx

服务管理:

启动:

systemctl start nginx 

停止:

systemctl stop nginx 

重启:

systemctl restart nginx

重新加载配置:

systemctl reload nginx

备注

有关 Nginx 基本设置的详细信息,请参阅 官方文档

使用 API 订购 Nginx

question_mark
Is there anything I can help you with?
question_mark
AI Assistant ×