nginx學習筆記0

今天正式開始學習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系列學習筆記。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章