Nginx 从入门到精通 · 第1篇:初识 Nginx
什么是 Nginx? Nginx(发音 “engine-x”)是一个高性能的 HTTP 和反向代理服务器,由俄罗斯程序员 Igor Sysoev 于 2004 年开源。它的设计目标是解决 C10K 问题——即同时处理一万个并发连接。 核心特点: 事件驱动架构:不同于 Apache 的进程/线程模型,Nginx 使用异步非阻塞 I/O,单进程可处理数万并发 高并发能力:轻松支撑数万并发连接 低内存消耗:同等负载下,内存占用远低于 Apache 模块化设计:功能通过模块扩展,可按需编译 安装 Nginx CentOS / RHEL # 添加 EPEL 源 sudo yum install epel-release -y # 安装 sudo yum install nginx -y # 启动 sudo systemctl start nginx sudo systemctl enable nginx Ubuntu / Debian sudo apt update sudo apt install nginx -y sudo systemctl start nginx sudo systemctl enable nginx 源码编译(进阶) # 安装依赖 sudo apt install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev # 下载并编译 wget https://nginx.org/download/nginx-1.26.0.tar.gz tar -zxvf nginx-1.26.0.tar.gz cd nginx-1.26.0 ./configure \ --prefix=/usr/local/nginx \ --with-http_ssl_module \ --with-http_gzip_static_module \ --with-http_stub_status_module make && sudo make install 启动与停止 # systemd 管理(推荐) sudo systemctl start nginx sudo systemctl stop nginx sudo systemctl reload nginx # 平滑重载配置 sudo systemctl restart nginx sudo systemctl status nginx # 直接使用二进制 sudo nginx # 启动 sudo nginx -s stop # 快速停止 sudo nginx -s quit # 优雅停止(处理完当前请求) sudo nginx -s reload # 平滑重载配置 sudo nginx -s reopen # 重新打开日志文件 验证安装 浏览器访问 http://服务器IP,看到 Welcome to nginx 页面即成功。 ...