首页 > 软件下载 > Nginx 1.19.9
Nginx

Nginx

nginx(发音同enginex)是一款由俄罗斯程序员IgorSysoev所开发轻量级的网页服务器、反向代理服务器以及电子邮件(IMAP/POP3)代理服务器。起初是供俄国大型的门户网站及搜索引擎Rambler(俄语:Рамблер)使用。,Nginx完美下载。

  • 软件大小:1.7 MB
  • 版本类型:官方稳定版
  • 更新时间:2022-01-28
  • 版本号:1.19.9
  • 软件语言:简体中文
  • 适用系统:Windows 7 及以上
  • 软件授权:免费

Nginx

版本 1.19.9 1.7 MB Windows 7 及以上

Nginx安装教程

nginx(发音同 engine x)是一款由俄罗斯程序员 Igor Sysoev 所开发轻量级的网页服务器、反向代理服务器以及电子邮件(IMAP/POP3)代理服务器。起初是供俄国大型的门户网站及搜索引擎 Rambler(俄语:Рамблер)使用。此软件 BSD-like 协议下发行,可以在 UNIX、GNU/Linux、BSD、Mac OS X、Solaris,以及 Microsoft Windows 等操作系统中运行。

nginx 不单可以作为强大的 web 服务器,也可以作为一个反向代理服务器,而且 nginx 还可以按照调度规则实现动态、静态页面的分离,可以按照轮询、ip 哈希、URL 哈希、权重等多种方式对后端服务器做负载均衡,同时还支持后端服务器的健康检查。

更新日志:

Nginx 1.7.7 发布了,下载地址:

改进记录包括:

*) Change: now nginx takes into account the "Vary" header line in a

backend response while caching.

*) Feature: the "proxy_force_ranges", "fastcgi_force_ranges",

"scgi_force_ranges", and "uwsgi_force_ranges" directives.

*) Feature: the "proxy_limit_rate", "fastcgi_limit_rate",

"scgi_limit_rate", and "uwsgi_limit_rate" directives.

*) Feature: the "Vary" parameter of the "proxy_ignore_headers",

"fastcgi_ignore_headers", "scgi_ignore_headers", and

"uwsgi_ignore_headers" directives.

*) Bugfix: the last part of a response received from a backend with

unbufferred proxy might not be sent to a client if "gzip" or "gunzip"

directives were used.

*) Bugfix: in the "proxy_cache_revalidate" directive.

Thanks to Piotr Sikora.

*) Bugfix: in error handling.

Thanks to Yichun Zhang and Daniil Bondarev.

*) Bugfix: in the "proxy_next_upstream_tries" and

"proxy_next_upstream_timeout" directives.

Thanks to Feng Gu.

*) Bugfix: nginx/Windows could not be built with MinGW-w64 gcc.

Thanks to Kouhei Sutou.

web 服务器 Nginx 发布 1.6.2。2014-09-16。上个版本 2014-08-05 的 1.6.1 遗留稳定版 1.4.7/1.2.9/1.0.15.开发版 1.7.5 修正了一个 SSL 相关的安全漏洞 (CVE-2014-3616),以及两个 DNS 可能导致请求挂起 Bug(1.5.8 引入)。

nginx 开发团队还同步发布了 nginx 1.7.0 主线版本,新特性如下:

后端 SSL 证书验证

当使用 SSL 后端时,支持 SNI(服务器名称标识符)

Nginx 顶级网站用量超越 Apache 位居第一

据 W3Techs 统计数据显示,全球 Alexa 排名前 100 万的网站中的 23.3% 都在使用 nginx,在排名前 10 万的网站中,这一数据为 30.7%,而在前 1000 名的网站中,nginx 的使用量超过了 Apache,位居第 1 位。

Nginx 负载均衡一些基础知识:

nginx 的 upstream 目前支持 4 种方式的分配
1)、轮询(默认)
每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器 down 掉,能自动剔除。
2)、weight
指定轮询几率,weight 和访问比率成正比,用于后端服务器性能不均的情况。
2)、ip_hash
每个请求按访问 ip 的 hash 结果分配,这样每个访客固定访问一个后端服务器,可以解决 session 的问题。
3)、fair(第三方)
按后端服务器的响应时间来分配请求,响应时间短的优先分配。
4)、url_hash(第三方)

按访问的 url 的 hash 结果分配,使每个 url 定向到同一个后端服务器,后端为缓存服务器比较有效。

配置:

在 http 节点里添加:

#定义负载均衡设备的 Ip 及设备状态

upstream myServer {

server 127.0.0.1:9090 down;
server 127.0.0.1:8080 weight=2;
server 127.0.0.1:6060;
server 127.0.0.1:7070 backup;
}

在需要使用负载的 Server 节点下添加

proxy_pass http://myServer;

upstream 每个设备的状态:

down 表示单前的 server 暂时不参与负载
weight 默认为 1.weight 越大,负载的权重就越大。
max_fails:允许请求失败的次数默认为 1.当超过最大次数时,返回 proxy_next_upstream 模块定义的错误
fail_timeout:max_fails 次失败后,暂停的时间。
backup:其它所有的非 backup 机器 down 或者忙的时候,请求 backup 机器。所以这台机器压力会最轻。

Nginx 还支持多组的负载均衡,可以配置多个 upstream 来服务于不同的 Server.

配置负载均衡比较简单,但是最关键的一个问题是怎么实现多台服务器之间 session 的共享

windows 和 Linux 下配置 Nginx 负载的写法一样,故不分开介绍。

启动

绿色文件,无须安装,直接即可启动。

据我所知,3 种启动途径,其实都类似:

一、双击 nginx.exe 图标,可见黑窗口一闪而过,启动完毕。

二、命令行到 nginx 目录,输入 nginx 启动。(注,此方式命令行窗口无任何提示,且被锁定)

三、命令行到 nginx 目录,输入 start nginx 启动,此方式不锁定

启动后,默认情况下(无修改配置),可见到有两个 nginx 的进程,一个是 master process,一个是 worker processes。

测试

默认 nginx 部署了些静态内容,我们可通过它测试 nginx 是否在工作。

默认的配置文件(NGINX_HOME/conf/nginx.conf)如下:

#user nobody;

worker_processes 1;

#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

#pid logs/nginx.pid;

events {

worker_connections 1024;

}

http {

include 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 logs/access.log main;

sendfile on;

#tcp_nopush on;

#keepalive_timeout 0;

keepalive_timeout 65;

#gzip on;

server {

listen 80;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

root html;

index index.html index.htm;

}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

# proxy_pass http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

#location ~ \.php$ {

# root html;

# fastcgi_pass 127.0.0.1:9000;

# fastcgi_index index.php;

# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

# include fastcgi_params;

#}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

# deny all;

#}

}

# another virtual host using mix of IP-, name-, and port-based configuration

#

#server {

# listen 8000;

# listen somename:8080;

# server_name somename alias another.alias;

# location / {

# root html;

# index index.html index.htm;

# }

#}

# HTTPS server

#

#server {

# listen 443 ssl;

# server_name localhost;

# ssl_certificate cert.pem;

# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;

# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;

# ssl_prefer_server_ciphers on;

# location / {

# root html;

# index index.html index.htm;

# }

#}

}

通过观察配置文件的非注释项(参考 Nginx 配置文件 nginx.conf 中文详解),大概可知:

1、启动了 1 个 worker processes

2、worker_connections,最大并发数为 1024

3、include mime.types,引入 mime.types 文件所声明的文件扩展名与文件类型映射

4、application/octet-stream,默认使用 application/octet-stream

5、sendfile,开启高效文件传输模式

6、监听本机“localhost”的 80 端口

7、映射目录为“当前目录的 html 目录”

8、出现 500、502、503、504 错误,则映射到 50x.html

浏览地址http://localhost,即可访问其默认页面,即映射到NGINX_HOME/html/index.html

其他静态内容,如 html、图片,可自行添加测试。

日志

日志默认位于 NGINX_HOME/logs/,可见:

1、access.log,访问日志

2、error.log,异常日志

3、nginx.pid,进程(仅在启动 nginx 后才有此日志)