nginx優化後的主配置文件

user web web;                #nginx的程序帳戶和程序組          
worker_processes auto;           #worker進程數 auto設爲默認 

error_log /app/logs/nginx/wwwlogs/error_nginx.log crit;        #錯誤日誌保存在哪裏
pid /var/run/nginx.pid;                #進程號
google_perftools_profiles /tmp/tcmalloc;        #google_perftools工具優化Nginx和MySQL的內存管理javascript

      
worker_rlimit_nofile 51200;          #nginx worker進程最大打開文件數 

events {
        use epoll;            #使用epoll異步網絡IO模型
        worker_connections 51200;    #每一個worker支持的最大鏈接數
        }

http {
        log_format  main  '$host $remote_addr [$time_local] '      #記錄日誌的格式   $remote_addr客戶端IP[$time_local]訪問時間
                  '$status $body_bytes_sent "$http_referer" '        #$status 狀態碼$body_bytes_sent響應body大小 "$http_referer"請求是從哪一個鏈接來的
                  '"$http_user_agent" "$http_x_forwarded_for" '    #"$http_user_agent"記錄客戶端訪問信息 如瀏覽器手機端等 "$http_x_forwarded_for"在有代理的狀況下開啓
                  '$upstream_addr "$upstream_cache_status"';    #$upstream_addr "$upstream_cache_status"顯示緩存的狀態'
        include mime.types;                  #Nginx支持的媒體類型庫文件包含
        default_type application/octet-stream;          #默認的媒體類型
        server_names_hash_bucket_size 128;          #優化服務器域名的散列表大小定義服務器名字的hash表大小      
        client_header_buffer_size 32k;             #上傳文件大小限制
        large_client_header_buffers 4 32k;            #設定請求緩存         
        client_max_body_size 50m;                #設定請求緩存
        sendfile on;                      ##開啓高效文件傳輸模式,sendfile指令指定nginx是否調用sendfile函數來輸出文件,對於普通應用設爲 on,若是用來進行下載等應用磁盤IO重負載應用,可設置爲off,以平衡磁盤與網絡I/O處理速度,下降系統的負載。注意:若是圖片顯示不正常把這個改爲off。
        tcp_nopush on;                     #防止網絡阻塞  開啓sendfile on 才能使用                  
        keepalive_timeout 120;                 #長鏈接超時時間,單位是秒
        server_tokens off;                    #隱藏版本信息
        tcp_nodelay on;                    #防止網絡阻塞
     #如下爲fastcgi即php-ftm優化 
        fastcgi_connect_timeout 300;              #nginx服務與後端php服務鏈接超時時間 不建議設置過高             
        fastcgi_send_timeout 300;                #在規定時間內php後端必須將數據上傳至nginx 超時斷開鏈接
        fastcgi_read_timeout 300;                #nginx從php讀取信息的超時時間 是nginx進入後端之中排隊的等候處理時間
        fastcgi_buffer_size 64k;                 #這是nginx的fastcgi緩存大小
        fastcgi_buffers 4 64k;                  #從fastcgi服務端收到的響應信息的緩衝區大小和緩衝區數量 4個64K的內存
        fastcgi_busy_buffers_size 128k;              #用於設定系統很忙時設定的proxy_buffers大小
        fastcgi_temp_file_write_size 128k;             #fastcgi臨時文件的大小
  #如下爲gzip網頁壓縮
        gzip on;                      #開啓gzip網頁壓縮
        gzip_buffers 16 8k;                  #申請 16個8k的內存內存做爲壓縮結果流緩存
        gzip_comp_level 6;                  #壓縮等級爲6級
        gzip_http_version 1.1;                 #http協議版本1.1
        gzip_min_length 256;                 #設置容許壓縮的頁面最小字節數
        gzip_proxied any;                  #設置將被gzip壓縮的響應的最小長度 any爲全部代理請求啓用壓縮。
        gzip_vary on;                 #讓前端緩存服務器通過gzip壓縮的頁面
        gzip_types                  #壓縮類型對哪些網頁文檔啓用壓縮功能            
            text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
            text/javascript application/javascript application/x-javascript
            text/x-json application/json application/x-web-app-manifest+json
            text/css text/plain text/x-component
            font/opentype application/x-font-ttf application/vnd.ms-fontobject
            image/x-icon;
        gzip_disable  "msie6";          #對具備與任何指定正則表達式匹配的「User-Agent」標頭字段的請求禁用gzipping響應。


        open_file_cache max=1000 inactive=20s;      #最多緩存多少個文件,緩存多少時間
        open_file_cache_valid 30s;            #在30S中沒有使用到這個配置的次數的話就刪除
        open_file_cache_min_uses 2;           #指定不在活動期裏最小文件數
        open_file_cache_errors on;          #指令指定是否在搜索一個文件是記錄cache錯誤.php



#如下爲nginx反向代理相關配置
        proxy_connect_timeout 5;
        proxy_read_timeout 60;
        proxy_send_timeout 5;
        proxy_buffer_size 64k;
        proxy_buffers 4 64k;
        proxy_busy_buffers_size 128k;
        proxy_temp_file_write_size 128k;
        proxy_temp_path /app/data/temp_dir;
        proxy_cache_path /app/data/cache levels=1:2 keys_zone=cache_one:8g inactive=30d max_size=500g;


        include vhost/*.conf;
}

 css

相關文章
相關標籤/搜索