nginx(发音同enginex)是一款由俄罗斯程序员IgorSysoev所开发轻量级的网页服务器、反向代理服务器以及电子邮件(IMAP/POP3)代理服务器。起初是供俄国大型的门户网站及搜索引擎Rambler(俄语:Рамблер)使用。此软件BSD-like协议下发行,可以在UNIX、GNU/Linux、BSD、MacOSX、Solaris,以及MicrosoftWindows等操作系统中运行。
nginx不单可以作为强大的web服务器,也可以作为一个反向代理服务器,而且nginx还可以按照调度规则实现动态、静态页面的分离,可以按照轮询、ip哈希、URL哈希、权重等多种方式对后端服务器做负载均衡,同时还支持后端服务器的健康检查。
更新日志:
Nginx1.7.7发布了,下载地址:
改进记录包括:
*)Change:nownginxtakesintoaccountthe"Vary"headerlineina
backendresponsewhilecaching.
*)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"parameterofthe"proxy_ignore_headers",
"fastcgi_ignore_headers","scgi_ignore_headers",and
"uwsgi_ignore_headers"directives.
*)Bugfix:thelastpartofaresponsereceivedfromabackendwith
unbufferredproxymightnotbesenttoaclientif"gzip"or"gunzip"
directiveswereused.
*)Bugfix:inthe"proxy_cache_revalidate"directive.
ThankstoPiotrSikora.
*)Bugfix:inerrorhandling.
ThankstoYichunZhangandDaniilBondarev.
*)Bugfix:inthe"proxy_next_upstream_tries"and
"proxy_next_upstream_timeout"directives.
ThankstoFengGu.
*)Bugfix:nginx/WindowscouldnotbebuiltwithMinGW-w64gcc.
ThankstoKouheiSutou.
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开发团队还同步发布了nginx1.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及设备状态
upstreammyServer{
server127.0.0.1:9090down;server127.0.0.1:8080weight=2;server127.0.0.1:6060;server127.0.0.1:7070backup;}
在需要使用负载的Server节点下添加
proxy_pass?https://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目录,输入startnginx启动,此方式不锁定
启动后,默认情况下(无修改配置),可见到有两个nginx的进程,一个是masterprocess,一个是workerprocesses。
测试
默认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;
#charsetkoi8-r;
#access_log?logs/host.access.log?main;
location/{
root?html;
index?index.htmlindex.htm;
}
#error_page?404???????/404.html;
#redirectservererrorpagestothestaticpage/50x.html
#
error_page?500502503504?/50x.html;
location=/50x.html{
root?html;
}
#proxythePHPscriptstoApachelisteningon127.0.0.1:80
#
#location~\.php${
#??proxy_pass?https://127.0.0.1;
#}
#passthePHPscriptstoFastCGIserverlisteningon127.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;
#}
#denyaccessto.htaccessfiles,ifApache'sdocumentroot
#concurswithnginx'sone
#
#location~/\.ht{
#??deny?all;
#}
}
#anothervirtualhostusingmixofIP-,name-,andport-basedconfiguration
#
#server{
#??listen???8000;
#??listen???somename:8080;
#??server_name?somename?alias?another.alias;
#??location/{
#????root?html;
#????index?index.htmlindex.htm;
#??}
#}
#HTTPSserver
#
#server{
#??listen???443ssl;
#??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.htmlindex.htm;
#??}
#}
}
通过观察配置文件的非注释项(参考Nginx配置文件nginx.conf中文详解),大概可知:
1、启动了1个workerprocesses
2、worker_connections,最大并发数为1024
3、includemime.types,引入mime.types文件所声明的文件扩展名与文件类型映射
4、application/octet-stream,默认使用application/octet-stream
5、sendfile,开启高效文件传输模式
6、监听本机“localhost”的80端口
7、映射目录为“当前目录的html目录”
8、出现500、502、503、504错误,则映射到50x.html
浏览地址https://localhost,即可访问其默认页面,即映射到NGINX_HOME/html/index.html
其他静态内容,如html、图片,可自行添加测试。
日志
日志默认位于NGINX_HOME/logs/,可见:
1、access.log,访问日志
2、error.log,异常日志
3、nginx.pid,进程(仅在启动nginx后才有此日志)
Tags:Nginx,Web服务器.
小编点评:局域网远程控制TightVNC是一.
下载小编点评:楚乔传鹦鹉无水印表情包是出自特工皇妃楚.
下载小编点评:uRexVideomarkPlat.
下载小编点评:LeawoTotalMediaCo.
下载小编点评:MalwarebytesAnti-.
下载小编点评:傲梅轻松备份是一款免费的、简单易用的备份.
下载小编点评:法医视频报告软件ForensicV.
下载小编点评:MicrosoftWebDeploy—一.
下载小编点评:最好用的网站图片下载软件,只要指定一个起始网页.
下载小编点评:送你一朵小发发的表情包,是有着一套送花的.
下载小编点评:上海挂号网APP是一款非常不错的专.
下载小编点评:火牛智能剪辑是一款视频剪辑软件,可.
下载小编点评:百度云提取码.exe是使用Python.
下载网页图片缓存查看(FBCacheView)
搜索引擎排名查询器
魔兽地图:村庄幸存者2v1.04
ACGの竞技场1.79正式版
coreldraw x8 64位中文版|CorelDRAW Graphics Suite X8(coreldraw x8 64位版矢量图形设计软件下载)64位V18.0.0.448中文版下载
华创进销存管理系统V6.6下载
PE软件包配置文件生成助手(PESPA)V1.0下载
WAV to MP3 Converter绿色免费版(wav转mp3)V1.0.1下载
吐司传情专家(支持QQ/MSN)V2.0.0.0下载
主管技师考试宝典(输血技术)下载V11.0下载
Access Remote PC V5.1.0.0下载
xps阅读器(xps viewer下载)V1.1.0下载
LojiklSweep V2.13.0下载