1. 程式人生 > >第十六篇 nginx主配置文件參數解釋

第十六篇 nginx主配置文件參數解釋

cti sha md5 均衡 127.0.0.1 keepalive ase tp服務器 十六

  1 # 指定擁有運行nginx權限的用戶
  2 #user  nobody;   
  3 
  4 # 指定開啟的進程數,建議設置為CPU核心數
  5 worker_processes  1;  
  6 
  7 # 指定全局錯誤日誌級別,包括:debug/info/notice/warn/error/crit
  8 #error_log  logs/error.log;
  9 #error_log  logs/error.log  notice;
 10 #error_log  logs/error.log  info;
 11 
 12 # 指定nginx的主進程id的存儲位置
 13 pid        logs/nginx.pid;
14 15 # 一個nginx進程最多能打開的文件描述符數目,理論上應該等於系統最多能打開的文件數與nginx進程數相除 16 worker_rlimit_nofile 65535; 17 18 19 20 events { 21 22 # 指定工作模式 23 # epoll使Linux2.6以上版本的高性能網絡I/O模型 24 # 如果跑在FreeBSD上面,使用kqueue模型 25 use epoll; 26 27 # 指定每個進程的最大連接數,受系統進程的最大打開文件數量限制 28 worker_connections 1024
; 29 } 30 31 32 33 # 配置http服務器 34 http { 35 # 文件擴展名與文件類型映射表 36 include mime.types; 37 38 # 指定默認文件類型,這裏設置為二進制流 39 default_type application/octet-stream; 40 41 # 指定默認編碼 42 #charset utf-8; 43 44 # 指定服務器名字的hash表大小 45 #server_name_hash_bucket_size 128
; 46 47 # 指定允許客戶端請求的最大單個文件字節數 48 #client_max_body_size 20M; 49 50 # 指定客戶端請求頭的headerbuffer大小 51 #client_header_buffer_size 32k; 52 53 # 指定客戶端請求試圖寫入緩存文件的目錄路徑 54 #client_body_temp_path /dev/shm/client_body_temp; 55 56 # 指定客戶端請求中較大的消息頭的緩存最大數量和大小 57 #large client_header_buffers 4 32k; 58 59 #log_format main $remote_addr - $remote_user [$time_local] "$request" 60 # $status $body_bytes_sent "$http_referer" 61 # "$http_user_agent" "$http_x_forwarded_for"; 62 63 #access_log logs/access.log main; 64 65 # 開啟高效文件傳輸模式 66 sendfile on; 67 # 開啟防止網絡阻塞 68 tcp_nopush on; 69 # 開啟防止網絡阻塞 70 tcp_nodely on; 71 72 # 指定連接超時時間,單位是秒 73 #keepalive_timeout 0; 74 keepalive_timeout 65; 75 # 指定讀取請求header超時時間 76 #client_header_timeout 10; 77 # 指定讀取請求body超時時間 78 #client_body_timeout 20; 79 80 81 # http的gzip模塊配置 82 83 # 開啟gzip壓縮 84 #gzip on; 85 86 # 指定最小壓縮文件大小 87 #gzip_min_length 1k; 88 89 # 申請4個大小為16k的內存空間作為壓縮緩沖區 90 #gzip_buffers 4 16k; 91 92 # 設置識別http協議的版本,默認為1.1 93 #gzip_http_version 1.1 94 95 # 指定gzip壓縮比,1-9,數字越小壓縮比越小,壓縮速度越快 96 #gzip_comp_level 2; 97 98 # 指定壓縮類型 99 # 默認已包含text/html,如果再次指定,會有一個warn 100 #gzip_type text/plain application/x-javascript text/css application/xml; 101 102 #gzip_vary on; 103 104 105 # upstream用於實現負載均衡 106 # weight表示權重,值越大分配到的幾率越大 107 upstream fisher { 108 server 127.0.0.1:5001 weight=2; 109 server 127.0.0.1:5002 weight=3; 110 server 127.0.0.1:5003 weight=4; 111 } 112 113 114 # 虛擬主機配置 115 server { 116 117 # 指定監聽端口 118 listen 80; 119 120 # 指定域名,若有多個,用空格隔開 121 server_name localhost; 122 123 # 指定編碼 124 #charset koi8-r; 125 126 # 指定虛擬主機訪問日誌的存放路徑,日誌格式為main 127 #access_log logs/host.access.log main; 128 129 # 配置虛擬主機的基本信息 130 location / { 131 # 設置虛擬主機的網站根目錄 132 root html; 133 # 設置虛擬主機默認訪問的網頁 134 index index.html index.htm; 135 proxy_pass http://fisher; 136 } 137 138 #error_page 404 /404.html; 139 140 # redirect server error pages to the static page /50x.html 141 # 142 error_page 500 502 503 504 /50x.html; 143 location = /50x.html { 144 root html; 145 } 146 147 # proxy the PHP scripts to Apache listening on 127.0.0.1:80 148 # 149 #location ~ \.php$ { 150 # proxy_pass http://127.0.0.1; 151 #} 152 153 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 154 # 155 #location ~ \.php$ { 156 # root html; 157 # fastcgi_pass 127.0.0.1:9000; 158 # fastcgi_index index.php; 159 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 160 # include fastcgi_params; 161 #} 162 163 # deny access to .htaccess files, if Apaches document root 164 # concurs with nginxs one 165 # 166 #location ~ /\.ht { 167 # deny all; 168 #} 169 } 170 171 172 # another virtual host using mix of IP-, name-, and port-based configuration 173 # 174 #server { 175 # listen 8000; 176 # listen somename:8080; 177 # server_name somename alias another.alias; 178 179 # location / { 180 # root html; 181 # index index.html index.htm; 182 # } 183 #} 184 185 186 # HTTPS server 187 # 188 #server { 189 # listen 443 ssl; 190 # server_name localhost; 191 192 # ssl_certificate cert.pem; 193 # ssl_certificate_key cert.key; 194 195 # ssl_session_cache shared:SSL:1m; 196 # ssl_session_timeout 5m; 197 198 # ssl_ciphers HIGH:!aNULL:!MD5; 199 # ssl_prefer_server_ciphers on; 200 201 # location / { 202 # root html; 203 # index index.html index.htm; 204 # } 205 #} 206 207 }

第十六篇 nginx主配置文件參數解釋