1. 程式人生 > 其它 >|NO.Z.00068|——————————|LinuxNetwork|——|Linux&Nginx&反向代理.V04|-----------------------------------------|Nginx.conf詳解|

|NO.Z.00068|——————————|LinuxNetwork|——|Linux&Nginx&反向代理.V04|-----------------------------------------|Nginx.conf詳解|



[LinuxNetworkEnd:Linux&Nginx&反向代理.V04]                                            [Applications.LinuxNetworkEnd] [|nginx服務詳解|nginx狀態統計|目錄保護|基於IP並再次訪問統計頁面|] [建立虛擬機器|nginx反向代理|nginx負載均衡|實現https|]








一、nginx.conf配置檔案詳解
### --- nginx.conf配置檔案詳解


[root@server11 ~]# vim /usr/local/nginx/conf/nginx.conf
user  www www;
#程式執行使用者和組

worker_processes  auto;
#啟動程序,指定nginx啟動的工作程序數量,建議按照CPU數量來指定,一般等於CPU核心數目

error_log  /home/wwwlogs/nginx_error.log crit;
#全域性錯誤日誌

pid        /usr/local/nginx/logs/nginx.pid;
#主程序PID儲存檔案

worker_rlimit_nofile 51200;
#檔案描述符數量

events 
	  {
      use epoll;
      #使用epoll模型,對於2.6以上的核心,建議使用epoll模型以提高效能。
   	
	  worker_connections 51200;
      #工作程序的最大連線數量,根據硬體調整,和前面工作程序配置起來用,儘量大,但是別把CPU跑到100%就行每個程序允許的最大連線數,理論行每臺nginx伺服器的最大連線數為worker_processes*worker_connections,具體還要看伺服器的硬體、寬頻等。
      }
http 
#整體環境配置-網站配置
{
    include       mime.types;
    default_type  application/octet-stream;
	#設定mime型別,檔案傳遞型別由mime.type檔案定義
  	server_names_hash_bucker_size 128;
    #儲存伺服器名字的hash表大小
    client_header_buffer_size 32k;
    #客戶端請求頭部緩衝區大小
    large_client_header_buffers 4 32k;
    #最大客戶端頭緩衝大小
    client_max_body_size 50m;
    #客戶端最大上傳檔案大小(M)
    sendfile on;
    #sendfile指定指定nginx是否呼叫sendfile函式來輸出檔案,對於普通應用,必須設為on,如果用來進行下載等應用磁碟IO重負載應用,可設定為off,以平衡磁碟與網路I/O處理速度,降低系統的uptime.
    tcp_nopush  on;
    #這個是預設的,結果就是資料包不會馬上傳送出去,等到資料包最大時,一次性的傳輸出去,這樣有助於解決網路堵塞,(只在sendfile on時有效)
    
    keepalive_timeout  60;
    #連線超時時間
   
    tcp_nodelay on
    #禁止nagle演算法,也既不快取資料,有效解決網路阻塞
	fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64K;
    fastcfi_busy_buffers_size 128k;
    fastcfi_temp_file_write_size 256l;
    #fastcfi設定
    
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 416k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_tupes  text/plain application/javascrpt application/x-javascript text/javascript text/css application/xml application xml+rss;
    gzip_vary on;
    gzip_proxied expired no_cache no_store private auth;
    gzip_disable "MSIE[1-6]\.";
    
    #limit_conn_zone $binary_remote_addr zone=perip:10m;
    #If enable limit_conn_zone,add"limit_conn perip 10;" to server section.
    server_tokens off;
    #隱藏nginx版本號(curl -I 192.。168.4.154可以檢視,更加安全)
    
    #log format
    log_format access "$remote_addr -$remote_user [$time_local]"$request""
    '$status $body_bytes_sent "$http_referer"'
    ""$http_user_agent"$http_x_forwarded_for';
    #定義日誌格式
    
server
		{
            listen 80 default_server;
            #listen[::]:80 default_server ipb6only=on;
            #監聽80埠,web伺服器的監聽設定,可以採用“IP地址:埠"形式
            server_name www.lnmp.org lnmp.org;
            #伺服器名,可以寫多個域名,用空格分隔
            index index.html index.htm index.php;
            #預設網頁檔案
            root /home/wwwroot/default;
            #網頁主目錄
            
            #error_page 404 /404.html;
            include enable-php.conf;
            
            location /nginx_status
				        {
                          sub_status on;
                           access_log  off;
           #開啟status狀態監測
           location ~.*\(gif|jpg|jpeg|png|bmp|swf)$
          				 {
                             expires  30d;
                         }
           #靜態檔案處理,儲存期30天;
           location~.*\(js|css)?$
                            {
           						expires 		12h;
                             }
           #js和css檔案處理,儲存期為12小時
           location~^
              		 {
               				deny all;
          			 }
            access_log /home/wwwlogs/access.log access;
            #正確訪問日誌
            
include vhost/*.conf;
#vhost/xia 子配置檔案生效
}








===============================END===============================


Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart                                                                                                                                                    ——W.S.Landor



來自為知筆記(Wiz)