nginx学习笔记0

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zyf837368104/article/details/7621828
今天正式开始学习nginx,nginx以前是接触过,不过都是照着教程来的,今天一定要好好学一下!
我将分好几次分别记录我学习nginx的历程。
本文参考马哥的nginx教程  而写的笔记

http://news.netcraft.com/
这个是一个统计当前web服务器的各种信息的网站!


由上图可知,nginx稳坐第三名,群众的眼睛都是雪亮的!nginx会超过微软的IIS!

http://nginx.org/ 官方网站
nginx采用epoll事件模型(内核2.6以上支持!),I/O效率相当高!(Apache采用select机制,稳定)
具体为什么可以参看
http://www.cppblog.com/converse/archive/2008/10/12/63836.html
http://xinlogs.com/nginx-epool-events

nginx [engine x] is anHTTP and reverse proxy server,as well as a mail proxy server, written byIgor Sysoev. For a long time, it has been runningon many heavily loaded Russian sites includingYandex,Mail.Ru,VKontakte, andRambler. According to Netcraft nginx served orproxied10.09% busiest sites in April 2012. Here are someof the success stories:FastMail.FM,Wordpress.com.

读法,enginex 貌似我一直都读错的,擦泪!HTTP服务器,反向代理(proxy)服务器,邮件反向代理,是个俄罗斯人写的,单台nginx服务器可以处理时5万个并发,Apache最多只能处理3000个,但是Apache稳定且功能众多,所以nginx做了众多网站的反向代理服务器,作为负载均衡,咱们精弘网络也是Apache做后台,tomcat处理jsp,而nginx处理静态页面!

The sources are distributed under the2-clause BSD-likelicense.
Basic HTTP server features
Serving static and index files, andautoindexing;open file descriptor cache;

处理静态主页,自动索引,作为文件描述符的缓存,这样再次访问特别快!
Accelerated reverse proxying with caching;simple load balancing and fault tolerance;
用cache加速反向代理!(这里可以对比一下squid服务!squid与apache相同属于重量级的反向代理,一次相对有varnish这款缓存在内存中的!)

Accelerated support with caching ofFastCGI, uwsgi, SCGI, andmemcached servers;simple load balancing and fault tolerance;

memcached是分布式的内存缓存服务器!fastcgi(php)uwsgi(python)nginx本身的缓存机制不如varnish等,varnish与squid的缓存能力很强!而nginx对于HTTP请求的处理能力很强!通常的架构一般是这样的:前端nginx只做反向代理处理HTTP请求,不做任何缓存。后端直接指向varnish或squid做为缓存,在后面是Apache实现web应用!所以没有一种超级NB的服务软件的把所有事都给干了,所以想要有市场份额,你就必须有超出其他服务的特长!做人亦如此!

Modular architecture. (模块化)Filters includegzipping, byte ranges, chunked responses,XSLT,SSI, andimage transformation filter. Multiple SSIinclusions within a single page can be processed in parallel if they arehandled by proxied or FastCGI servers;
SSL and TLS SNI support.

淘宝使用nginx,但是对于淘宝这么夸张的pv数,nginx某些时候不够用,淘宝就针对这个再做了 一个tengine的web服务器!
官网如下,http://tengine.taobao.org/index_cn.html (tengine是开源产品哦!来自淘宝核心系统开发部门,让偶想起了上次的OceanBase!)

Other HTTP server features
Name-based and IP-basedvirtual servers;

基于域名或者IP的虚拟主机

Keep-alive and pipelined connectionssupport;
Flexible configuration;
Reconfiguration andupgradeof an executable without interruption of the client servicing;

重写配置,可以不打断当前用户请求

Access log formats,buffered log writing, andfastlog rotation;

日志格式,可以缓存日志!(日志会涉及磁盘读写,可以先缓存,在一次写入,提高磁盘效率),支持快速日志滚动!

3xx-5xx error codesredirection;

自定义错误页面,我们的404,500等错误页面

The rewrite module:URI changing using regular expressions;

重写模块,URI(同一资源定位符)
根据url,域名的不同,将http请求发到不同的服务器分组

Executing different functions depending ontheclient address;

基于客户端地址的不同执行不同的功能模块

Access control based onclient IP address andHTTP Basic authentication;
Validation ofHTTP referer;
ThePUT, DELETE, MKCOL, COPY, and MOVE methods;
FLV andMP4 streaming;

各种流媒体视频格式

Response rate limiting;

响应速度限制,例如:凡是来自于上海的IP响应为5K/s,杭州的500K/s

Limiting the number of simultaneousconnections orrequests coming from one address;

Embedded Perl.

可以启用Perl(啊!)

Mail proxy server features
User redirection to IMAP/POP3 backend using an external HTTP authenticationserver;
User authentication using an external HTTP authentication server and connectionredirection to an internal SMTP backend;

  • Authentication methods:
  •  
  • POP3: USER/PASS, APOP, AUTH LOGIN/PLAIN/CRAM-MD5;
  • IMAP: LOGIN, AUTH LOGIN/PLAIN/CRAM-MD5;
  • SMTP: AUTH LOGIN/PLAIN/CRAM-MD5;
  • SSL support;
  • STARTTLS and STLS support.

Architecture and scalability

  • One master and several worker processes; worker processes run under an unprivileged user;
  • The notification methods: kqueue (FreeBSD 4.1+), epoll (Linux 2.6+), rt signals (Linux 2.2.19+), /dev/poll (Solaris 7 11/99+), event ports (Solaris 10), select, and poll;
  • 各种机制,你说咋就没Windows呢?!
  • The support of the various kqueue features including EV_CLEAR, EV_DISABLE (to temporarily disable events), NOTE_LOWAT, EV_EOF, number of available data, error codes;
  • sendfile (FreeBSD 3.1+, Linux 2.2+, Mac OS X 10.5+), sendfile64 (Linux 2.4.21+), and sendfilev (Solaris 8 7/01+) support;
  • 啥叫sendfile?用户空间与内核空间的切换!

(FreeBSD 4.3+, Linux 2.6.22+);

(FreeBSD 4.4+, Linux 2.4+, Solaris 2.6+, Mac OS X);

  • Accept-filters (FreeBSD 4.1+) and TCP_DEFER_ACCEPT (Linux 2.4+)support;
  • 10,000 inactive HTTP keep-alive connections take about 2.5M memory;
  • 10000的HTTP在线请求仅占用2.5M内存!
  • Data copy operations are kept to a minimum.

Tested OS and platforms

  • FreeBSD 3 — 10 / i386; FreeBSD 5 — 10 / amd64;
  • Linux 2.2 — 3 / i386; Linux 2.6 — 3 / amd64;
  • Solaris 9 / i386, sun4u; Solaris 10 / i386, amd64, sun4v;
  • AIX 7.1 / powerpc
  • Mac OS X / ppc, i386;
  • Windows XP, Windows Server 2003.

虽然上面讲了这么多,但nginx并非牛上了天,要不然Apache也不是老大哥!
源码安装咱直接省略了(最新的1.2稳定版在4.23放出!)
关于memcached,这块需要好好学习!
memcached注意与memcache的区别,一个d哦!咱php的memcache是php的API!(重要哦)

各个语言都有各自的memcached客户端!
nginx也有memcached的客户端
大型web解决方案可以还有
CDN加速!(contentdelivery network)

智能DNS(DNSPOD,dns.la)

 

 

关于nginx的配置文件,请参考我其他的nginx系列学习笔记。


猜你喜欢

转载自blog.csdn.net/zyf837368104/article/details/7621828