天天看點

《深入了解Nginx:子產品開發與架構解析》一導讀

《深入了解Nginx:子產品開發與架構解析》一導讀

當我試圖在産品的關鍵位置設計一個高性能web伺服器時,我選擇使用成熟的nginx。選擇它的理由為:首先,它對伺服器性能上的挖掘已經達到了很高水準,它能盡量使不同的硬體(包括網卡、硬碟、不同的cpu核心)并發運作,同時軟體中又沒有阻塞程序使之睡眠的代碼,從性能上來說,它可以挑戰任何伺服器。其次,完全基于事件驅動的伺服器開發效率往往很不理想,它們要處理的事件過于底層化、細節化,這使得各功能子產品無法聚焦于業務,最終産品的功能都較為單一,不會有豐富的可選功能。但nginx卻不然,由于它在軟體架構上具有優秀的設計,使得nginx完全由許多簡單的子產品構成,各子產品(特别是http子產品)不用介入底層細節,在盡享分階段、無阻塞的事件驅動架構下,可以專注于業務功能的實作,這樣最終為nginx帶來了大量的官方、第三方的功能子產品,使得功能同樣強大的nginx在産品核心位置上足以擔當重任,經受住海量請求的考驗。

當nginx已有子產品提供的功能不能完全實作我的所有業務需求時,我可以在nginx的後端再搭建一個實作了缺失功能的非nginx伺服器,将nginx無法實作的請求反向代理到這台伺服器上處理。但這樣也有一定的弊端,首先增大了處理請求的開銷,其次後端伺服器的設計仍然制約着總體性能(它依然需要解決nginx解決過的無阻塞問題,那樣才能像nginx一樣高效),這樣做僅适用于對性能要求不高的場景。唯有開發一個實作了所需功能的自定義nginx子產品嵌入到nginx代碼中,才能讓自己的業務像nginx一樣充分挖掘伺服器的硬體資源,及時地響應百萬級别的并發tcp連接配接。

前 言

第一部分 nginx能幫我們做什麼

<a href="https://yq.aliyun.com/articles/176760">第1章 研究nginx前的準備工作</a>

<a href="https://yq.aliyun.com/articles/176760">1.1 nginx是什麼</a>

<a href="https://yq.aliyun.com/articles/176761">1.2 為什麼選擇nginx</a>

<a href="https://yq.aliyun.com/articles/176765">1.3 準備工作</a>

<a href="https://yq.aliyun.com/articles/176768">1.4 編譯安裝nginx</a>

<a href="https://yq.aliyun.com/articles/176790">1.5 configure詳解</a>

<a href="https://yq.aliyun.com/articles/176793">1.6 nginx的指令行控制</a>

<a href="https://yq.aliyun.com/articles/176795">1.7 小結</a>

<a href="https://yq.aliyun.com/articles/176798">第2章 nginx的配置</a>

<a href="https://yq.aliyun.com/articles/176798">2.1 運作中的nginx程序間的關系</a>

<a href="https://yq.aliyun.com/articles/176801">2.2 nginx配置的通用文法</a>

<a href="https://yq.aliyun.com/articles/176809">2.3 nginx服務的基本配置</a>

<a href="https://yq.aliyun.com/articles/176821">2.4 用http核心子產品配置一個靜态web伺服器</a>

<a href="https://yq.aliyun.com/articles/176827">2.5 用http proxy module配置一個反向代理伺服器</a>

<a href="https://yq.aliyun.com/articles/176828">2.6 小結</a>

第二部分 如何編寫http子產品

<a href="https://yq.aliyun.com/articles/176832">第3章 開發一個簡單的http子產品</a>

<a href="https://yq.aliyun.com/articles/176836">3.1 如何調用http子產品</a>

<a href="https://yq.aliyun.com/articles/176844">3.2 準備工作</a>

<a href="https://yq.aliyun.com/articles/176857">3.3 如何将自己的http子產品編譯進nginx</a>

<a href="https://yq.aliyun.com/articles/176876">3.4 http子產品的資料結構</a>

<a href="https://yq.aliyun.com/articles/176877">3.5 定義自己的http子產品</a>

<a href="https://yq.aliyun.com/articles/176878">3.6 處理使用者請求</a>

<a href="https://yq.aliyun.com/articles/176880">3.7 發送響應</a>

<a href="https://yq.aliyun.com/articles/176883">3.8 将磁盤檔案作為包體發送</a>

<a href="https://yq.aliyun.com/articles/176887">3.9 用c++語言編寫http子產品</a>

<a href="https://yq.aliyun.com/articles/176888">3.10 小結</a>

第4章 配置、error日志和請求上下文

4.1 http配置項的使用場景

4.2 怎樣使用http配置

4.2.1 配置設定用于儲存配置參數的資料結構

4.2.2 設定配置項的解析方式

4.2.3 使用14種預設方法解析配置項

4.2.4 自定義配置項處理方法

4.2.5 合并配置項

4.3 http配置模型

4.3.1 解析http配置的流程

4.3.2 http配置模型的記憶體布局

4.3.3 如何合并配置項

4.3.4 預設配置項處理方法的工作原理

4.4 error日志的用法

4.5 請求的上下文

4.5.1 上下文與全異步web伺服器的關系

4.5.2 如何使用http上下文

4.5.3 http架構如何維護上下文結構

4.6 小結

繼續閱讀