1. 首页 > 软件下载 > 正文

Web服务器下载-Nginx服务器下载地址-Nginx服务器下载方法

1. Nginx简介

Nginx是由Igor Sysoev开发的高性能HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。Nginx以其高性能、稳定性、丰富的功能集、简单的配置和低资源消耗而闻名。Nginx广泛应用于Web服务器、反向代理、负载均衡、HTTP缓存等场景。更多学习教程www.fgedu.net.cn

Nginx的主要特点包括:高并发处理能力、低内存消耗、反向代理和负载均衡、SSL/TLS支持、静态文件服务、FastCGI支持、虚拟主机、URL重写、Gzip压缩、缓存机制。

2. Nginx版本说明

Nginx提供两个版本系列,用户可根据需求选择:

主线版本(Mainline)

Nginx 1.29.7:最新主线版本,包含最新功能和安全修复

Nginx 1.29.4:主线版本,支持HTTP/2到后端和Encrypted ClientHello

稳定版本(Stable)

Nginx 1.28.1:最新稳定版本,2025-12-23发布

Nginx 1.28.0:稳定版本,2025-04-23发布

版本选择建议

主线版本:包含最新功能,适合需要新特性的场景

稳定版本:经过充分测试,适合生产环境

支持的平台

Linux:所有主流发行版

Windows:Windows Server 2012+

FreeBSD:12.x及以上

macOS:10.15及以上

版本选择建议:对于生产环境,建议使用稳定版本1.28.1。对于需要最新功能的场景,可以选择主线版本1.29.7。主线版本的中间版本号为奇数,稳定版本为偶数。

3. 官方下载方式

Nginx是完全开源免费的Web服务器,可直接从官网下载。学习交流加群风哥微信: itpux-com

官方下载地址

Nginx官网:https://nginx.org/

下载页面:https://nginx.org/en/download.html

中文官网:https://www.nginx.org.cn/

使用wget下载源码包

# 下载Nginx 1.28.1稳定版源码
$ wget https://nginx.org/download/nginx-1.28.1.tar.gz

# 输出示例如下:
–2026-04-04 10:15:00– https://nginx.org/download/nginx-1.28.1.tar.gz
Resolving nginx.org… 3.125.197.172
Connecting to nginx.org|3.125.197.172|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 1245678 (1.2M) [application/octet-stream]
Saving to: ‘nginx-1.28.1.tar.gz’

nginx-1.28.1.tar.gz 100%[===========================================>] 1.19M 5.5MB/s in 0.2s

# 验证下载文件
$ sha256sum nginx-1.28.1.tar.gz

# 输出示例如下:
abc123def456789… nginx-1.28.1.tar.gz

# 解压源码包
$ tar -xzf nginx-1.28.1.tar.gz

# 输出示例如下:
$ ls nginx-1.28.1/
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src

# 下载Nginx 1.29.7主线版源码
$ wget https://nginx.org/download/nginx-1.29.7.tar.gz

# 输出示例如下:
–2026-04-04 10:15:00– https://nginx.org/download/nginx-1.29.7.tar.gz
Resolving nginx.org… 3.125.197.172
Connecting to nginx.org|3.125.197.172|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 1256789 (1.2M) [application/octet-stream]
Saving to: ‘nginx-1.29.7.tar.gz’

nginx-1.29.7.tar.gz 100%[===========================================>] 1.20M 5.5MB/s in 0.2s

4. Docker安装方式

Docker是部署Nginx最简单的方式。from:www.itpux.com

# 拉取Nginx Docker镜像
$ docker pull nginx:1.28.1

# 输出示例如下:
1.28.1: Pulling from library/nginx
Digest: sha256:abc123def456…
Status: Downloaded newer image for nginx:1.28.1
docker.io/library/nginx:1.28.1

# 启动Nginx容器
$ docker run -d –name nginx \
-p 80:80 \
-p 443:443 \
-v /fgeudb/nginx/html:/usr/share/nginx/html \
-v /fgeudb/nginx/conf:/etc/nginx \
-v /fgeudb/nginx/logs:/var/log/nginx \
nginx:1.28.1

# 输出示例如下:
abc123def456789…

# 查看容器状态
$ docker ps

# 输出示例如下:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
abc123def456 nginx:1.28.1 “/docker-entrypoint.…” 5 seconds ago Up 4 seconds 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp nginx

# 测试访问
$ curl http://localhost

# 输出示例如下:

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.

风哥提示:Nginx Docker镜像默认配置文件位于/etc/nginx/nginx.conf,网站根目录位于/usr/share/nginx/html。建议使用数据卷挂载配置文件和网站目录,便于管理和修改。

5. 安装介质说明

Nginx提供多种安装介质,用户可根据实际需求选择。学习交流加群风哥QQ113257174

安装方式

源码编译:最灵活,可自定义模块

官方仓库:推荐生产环境使用

系统仓库:简单但版本可能较旧

Docker镜像:快速部署

使用官方仓库安装(RHEL/CentOS)

# 添加Nginx官方仓库
# cat > /etc/yum.repos.d/nginx.repo << 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 # 安装Nginx # yum install -y nginx # 输出示例如下: nginx-stable | 2.9 kB 00:00:00 nginx-stable/7/x86_64/primary_db | 87 kB 00:00:01 Resolving Dependencies --> Running transaction check
—> Package nginx.x86_64 1:1.28.1-1.el7.ngx will be installed
–> Finished Dependency Resolution

Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
nginx x86_64 1:1.28.1-1.el7.ngx nginx-stable 818 k

Transaction Summary
================================================================================
Install 1 Package

Total download size: 818 k
Installed size: 2.8 M
Downloading packages:
nginx-1.28.1-1.el7.ngx.x86_64.rpm | 818 kB 00:00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 1:nginx-1.28.1-1.el7.ngx.x86_64 1/1
———————————————————————-

Thanks for using nginx!

Please find the official documentation for nginx here:
* https://nginx.org/en/docs/

Commercial subscriptions for nginx are available on:
* https://nginx.com/products/

———————————————————————-
Verifying : 1:nginx-1.28.1-1.el7.ngx.x86_64 1/1

Installed:
nginx.x86_64 1:1.28.1-1.el7.ngx

Complete!

# 启动Nginx服务
# systemctl start nginx
# systemctl enable nginx

# 输出示例如下:
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

# 查看版本
# nginx -v

# 输出示例如下:
nginx version: nginx/1.28.1

源码编译安装

# 安装编译依赖
# yum install -y gcc pcre-devel zlib-devel openssl-devel

# 输出示例如下:
Package gcc-4.8.5-44.el7.x86_64 already installed and latest version
Package pcre-devel-8.32-17.el7.x86_64 already installed and latest version
Package zlib-devel-1.2.7-20.el7_9.x86_64 already installed and latest version
Package openssl-devel-1.0.2k-26.el7_9.x86_64 already installed and latest version
Nothing to do

# 解压并进入目录
$ tar -xzf nginx-1.28.1.tar.gz
$ cd nginx-1.28.1

# 配置编译选项
$ ./configure \
–prefix=/fgeudb/nginx \
–user=nginx \
–group=nginx \
–with-http_ssl_module \
–with-http_v2_module \
–with-http_realip_module \
–with-http_gzip_static_module \
–with-http_stub_status_module \
–with-stream \
–with-stream_ssl_module

# 输出示例如下:
checking for OS
+ Linux 3.10.0-1160.el7.x86_64 x86_64
checking for C compiler … found
+ using GNU C compiler
+ gcc version: 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
checking for gcc -pipe switch … found
checking for -Wl,-E switch … found
checking for gcc builtin atomic operations … found
checking for C99 variadic macros … found
checking for gcc variadic macros … found
checking for unistd.h … found
checking for inttypes.h … found
checking for limits.h … found
checking for sys/filio.h … not found
checking for sys/param.h … found
checking for sys/mount.h … found
checking for sys/statvfs.h … found
checking for crypt.h … found
checking for Linux specific features
checking for epoll … found
checking for EPOLLRDHUP … found
checking for EPOLLEXCLUSIVE … found
checking for O_PATH … found
checking for sendfile() … found
checking for sendfile64() … found
checking for sys/prctl.h … found

creating objs/Makefile

Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library

nginx path prefix: “/fgeudb/nginx”
nginx binary file: “/fgeudb/nginx/sbin/nginx”
nginx modules path: “/fgeudb/nginx/modules”
nginx configuration prefix: “/fgeudb/nginx/conf”
nginx configuration file: “/fgeudb/nginx/conf/nginx.conf”
nginx pid file: “/fgeudb/nginx/logs/nginx.pid”
nginx error log file: “/fgeudb/nginx/logs/error.log”
nginx http access log file: “/fgeudb/nginx/logs/access.log”
nginx http client request body temporary files: “client_body_temp”
nginx http proxy temporary files: “proxy_temp”
nginx http fastcgi temporary files: “fastcgi_temp”
nginx http uwsgi temporary files: “uwsgi_temp”
nginx http scgi temporary files: “scgi_temp”

# 编译安装
$ make
# make install

# 输出示例如下:
make -f objs/Makefile
make[1]: Entering directory `/root/nginx-1.28.1′
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I src/stream \
-o objs/src/core/nginx.o \
src/core/nginx.c

test -d ‘/fgeudb/nginx/logs’ || mkdir -p ‘/fgeudb/nginx/logs’
test -d ‘/fgeudb/nginx/html’ || cp -R html ‘/fgeudb/nginx’
test -d ‘/fgeudb/nginx/logs’ || mkdir -p ‘/fgeudb/nginx/logs’

6. 服务器配置方法

Nginx安装后需要进行基本配置,以下是常用配置方法。更多学习教程公众号风哥教程itpux_com

配置文件说明

# 编辑配置文件
# vi /etc/nginx/nginx.conf

# 基本配置示例
user nginx;
worker_processes auto;
worker_rlimit_nofile 65535;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;

events {
worker_connections 10240;
use epoll;
multi_accept on;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;

include /etc/nginx/conf.d/*.conf;
}

# 测试配置
# nginx -t

# 输出示例如下:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

# 重载配置
# nginx -s reload

# 输出示例如下:
# 查看进程
# ps aux | grep nginx

# 输出示例如下:
root 12345 0.0 0.1 123456 5678 ? Ss 10:30 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 12346 0.0 0.2 123456 8901 ? S 10:30 0:00 nginx: worker process
nginx 12347 0.0 0.2 123456 8901 ? S 10:30 0:00 nginx: worker process

虚拟主机配置

# 创建虚拟主机配置
# vi /etc/nginx/conf.d/fgedu.conf

server {
listen 80;
server_name fgedu.net.cn www.fgedu.net.cn;
root /fgeudb/www/fgedu;
index index.html index.htm;

access_log /var/log/nginx/fgedu.access.log main;
error_log /var/log/nginx/fgedu.error.log;

location / {
try_files $uri $uri/ =404;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 30d;
add_header Cache-Control “public, immutable”;
}

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

# 测试并重载配置
# nginx -t && nginx -s reload

# 输出示例如下:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

7. 生产环境建议

在生产环境中使用Nginx时,需要考虑以下因素:

性能优化配置

# 内核参数优化
# vi /etc/sysctl.conf

net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_max_syn_backlog = 8192
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 32768
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2

# 使配置生效
# sysctl -p

# 输出示例如下:
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200

# 文件描述符限制
# vi /etc/security/limits.conf

nginx soft nofile 65535
nginx hard nofile 65535

SSL/TLS配置

# HTTPS配置
server {
listen 443 ssl http2;
server_name fgedu.net.cn;

ssl_certificate /etc/nginx/ssl/fgedu.net.cn.crt;
ssl_certificate_key /etc/nginx/ssl/fgedu.net.cn.key;

ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

add_header Strict-Transport-Security “max-age=31536000; includeSubdomains” always;

location / {
proxy_pass http://192.168.1.51:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

# HTTP重定向到HTTPS
server {
listen 80;
server_name fgedu.net.cn;
return 301 https://$server_name$request_uri;
}

生产环境建议:Nginx适合作为Web服务器和反向代理,建议配置合理的worker进程数、启用Gzip压缩、配置SSL/TLS加密、设置适当的缓存策略、监控Nginx运行状态、配置日志轮转。

8. 常用模块推荐

Nginx提供丰富的模块扩展功能:

负载均衡配置

# 负载均衡配置
upstream backend {
ip_hash;
server 192.168.1.51:8080 weight=3;
server 192.168.1.52:8080 weight=2;
server 192.168.1.53:8080 backup;
keepalive 32;
}

server {
listen 80;
server_name fgedu.net.cn;

location / {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Connection “”;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_connect_timeout 60s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
}
}

# 健康检查(需要nginx-plus或第三方模块)
upstream backend {
zone backend 64k;
server 192.168.1.51:8080;
server 192.168.1.52:8080;
}

缓存配置

# 配置缓存路径
proxy_cache_path /fgeudb/nginx/cache levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m use_temp_path=off;

server {
listen 80;
server_name fgedu.net.cn;

location / {
proxy_cache my_cache;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
proxy_cache_key $scheme$request_method$host$request_uri;
add_header X-Cache-Status $upstream_cache_status;

proxy_pass http://backend;
}
}

风哥提示:Nginx是高性能Web服务器的首选,配置灵活,功能强大。建议根据实际需求选择合适的模块和配置参数。对于高并发场景,注意优化系统内核参数和Nginx配置。配合Keepalived可以实现高可用部署。

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息