1. 程式人生 > >nginx配置檔案中引數的作用

nginx配置檔案中引數的作用

####預設的nobody,沒有訪問目錄許可權,然後指定有許可權的使用者
####user  nobody;
####一般一個程序足夠了,你可以把連線數設得很大。
####如果有SSL、gzip這些比較消耗CPU的工作,而且是多核CPU的話,可以設為和CPU的數量一樣。
####或者要處理很多很多的小檔案,而且檔案總大小比記憶體大很多的時候,也可以把程序數增加,
####以充分利用IO頻寬(主要似乎是IO操作有block)。
worker_processes  1;

####error_log  logs/error.log;
####error_log  logs/error.log  notice;
####error_log logs/error.log info; ####用來存放當前程序的ID號 ####pid logs/nginx.pid; ####原來安裝好nginx之後,預設最大的併發數為1024,如果你的網站訪問量過大,已經遠遠超過1024這個併發數,那你就要修>改worker_connecions這個值 ,這個值越大,併發數也有就大。當然,你一定要按照你自己的實際情況而定,也不能設定太>大,不能讓你的CPU跑滿100%。 events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; ####如果需要日誌則把原來的註釋取消掉,main表示日誌的格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; ####access_log logs/access.log main; ####設定為on表示啟動高效傳輸檔案的模式。sendfile可以讓Nginx在傳輸檔案時直接在磁碟和tcp socket之間傳輸資料。>如果這個引數不開啟,會先在使用者空間(Nginx程序空間)申請一個buffer,用read函式把資料從磁碟讀到cache,再從cache讀取到使用者空間的buffer,再用write函式把資料從使用者空間的buffer寫入到核心的buffer,最後到tcp socket。開啟這個參
數後可以讓資料不用經過使用者buffer。 sendfile on; ####tcp_nopush on; ####keepalive_timeout 0; keepalive_timeout 65; ####gzip on; ####配置虛擬伺服器 server { ####配置埠號 listen 70; ####配置伺服器的名稱 server_name localhost; ####charset koi8-r; ####access_log logs/host.access.log main; #### "/":可以理解為是一個相對路徑 location / { ####頁面的路徑 root html; ####當前html路徑下的index.html index index.html; } error_page 500 502 503 504 /50x.html; #### "=":表示精準匹配 location = /50x.html { root html; } ####配置日誌路徑 access_log logs/access.log main; } ####如果有多個虛擬伺服器則配置多個server server { listen 18913; server_name test; location / { root test.com; index index.html; } access_log logs/test.com.access.log main; } }