nginx 配置優化(簡單)

配置文件

    正常運行的必備配置:
        1.user username [groupname];(推薦nginx)
        以那個用戶身份運行,以在configure指定的用戶爲準
        2.pid /path/to/pid_filename;
        指定nginx的pid文件
        3. worker_rlimit_nofile #;
        指定一個worker進程能打開的最大文件描述符數量;
        4. worker_rlimit_sigpending #;
        設定每一個用戶可以發往worker進程的信號的數量;
 
       
    autoindex on;   #開啓目錄瀏覽
    autoindex_exact_size off;  #關閉以byte顯示文件大小
    autoindex_localtime on;    #顯示的文件時間爲GMT時間
       

優化性能配置:

         1. worker_processes #;
                    worker進程的個數;一般爲物理cpu核心數量減1;
                       可能支持auto
         2.  worker_cpu_affinity  CPUMASK ;
                     CPUMASK:
                            00000001
                            00000010    
                worker_cpu_affinity  00000001  00000010 00000100;
         3. ssl_engine device;
            在存在ssl硬件加速器的服務器上,指定所使用的ssl硬件加速設備
 
         4. timer_resolution t
            每次內核事件調用返回時,都會使用gettimeofday()來更新nginx緩存時鐘;timer_resolution用於定義每隔多久纔會由gettimeofday()更新一次緩存時鐘; x86-64系統上,gettimeofday()代價已經很小,能夠忽略此配置
         5. worker_priority nice [-20~19]; 值越小越優先調用, 建議-10
 
 

跟事件相關的配置 events{}

        1.accept_mutex [on|off]
         是否打開nginx的負載均衡鎖;此鎖可以讓多個worker進行輪流地、序列化地與新的客戶端創建鏈接;而一般當一個worker進程的負載達到其上限的85%,master就儘量不在將請求調度此worker;
        2.lock_file /path/to/lock_file; 鎖文件
 
        3.accept_mutex_delay #ns;
         使用accept鎖之後,只有一個worker能取得鎖,一個worker進程爲取得accept鎖的等待時長,即用戶創建等待的時間,若是某worker進程在某次試圖取得鎖時失敗了,至少要等待#ns才能再一次請求鎖: 默認500毫秒
        4.multi_accept on|off;
        是否容許一次性地響應多個用戶請求, 默認爲off
        5. use [ epoll|rtsig|select|poll]
        指定使用那種模型, 建議讓nginx自動選擇
        6. worker_connections # ; worker_rlimit_nofile >=worker_connections
        每一個worker可以併發響應的最大請求數, 若是爲代理服務器的話,worker_rlimit_nofile=worker_commections*2
 

用於調試、定位問題:只調試nginx時使用

        1.daemon [on|off];
         關閉提供守護進程的模式,是否讓nignx運行於後臺;調試時應該爲off,使得全部信息直接輸出在控制檯,默認爲on
        2.master_process on|off
         是否以master/worker模式運行nginx,默認爲on,調試時能夠設置爲off以方便追蹤
        3.error_log /path/to/error_log  level
             (debug|info| notice | warn | error |crit|alert|emerg)
        錯誤日誌文件及其級別,調試時能夠使用debug級別,但要求在編譯時必須使用--with-debug啓用debug功能,默認一般爲error級別
相關文章
相關標籤/搜索