酷知百科網

位置:首頁 > 遊戲數碼 > 電腦

nginx 配置詳解

電腦1.61W

nginx是一個輕量級的反向代理服務器,收到很多開發者的喜愛。下面介紹一下nginx的的配置。

操作方法

(01)【基本組成】:xxxxxevents{xxxxx}http{xxxxxserver{xxxxx}server{xxxxx}xxxxx}

nginx 配置詳解
nginx 配置詳解 第2張

(02)【頭部】:user-是nginx進程用戶名;worker_processes-是nginx工作進程數量,建議設定爲cpu核心數量的2倍;pid-是nginx進程pid的存放檔案。

nginx 配置詳解 第3張

(03)【events部分】:worker_connections是每個工作進程允許最大的同時連接數 量。

nginx 配置詳解 第4張

(04)【http部分】:主要是server虛擬主機部分的配置。以下詳細講解。

nginx 配置詳解 第5張

(05)【nginx虛擬主機】:server{listen 端口;server_name ;......}server_name可以是ip地址也可以是域名,可以添加多個用空格分開。

(06)【日誌格式設定和路徑】:og_format設定日誌格式log_format name format [format ...]name:定義格式名稱format:定義格式樣式默認格式:combined '$remote_addr - $remote_user [$time_local]' '"$request" $status $body_bytes_sent  ' '"$http_referer" "$http_user_agent"';access_log 指定日誌檔案存放路徑access_log path [format [buffer=size | off]]path:檔案存放路徑format:log_format定義格式的名稱buffer:內存緩衝區大小使用默認格式:access_log path;使用緩衝加速日誌檔案讀寫:open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time] | off(默認)max:快取最大檔案描述符數量,超過使用LRU算法淘汰inactive:在inactive指定時間內檔案描述符沒有被使用則被自動刪除,默認10秒min_uses:在inactive指定時間內,檔案描述符超過min_uses使用次數,則加入快取,默認1valid:檢視變量指定的日誌檔案路徑與檔案是否存在的時間間隔,默認60秒

(07)【壓縮輸出】:gzip壓縮後變爲原來的<=30%配置:gzip on;gzip_min_length 1k;gzip_buffers 4 16k;gzip_http_version 1.1;gzip_comp_level 2;gzip_types text/plain application/x-javascript text/css application/xml;gzip_vary on;

nginx 配置詳解 第6張

(08)【自動列出目錄和location】:location / {autoindex on;開啟自動列出目錄autoindex_exact_size [on|off] 索引檔案大少單位(B KB MB GB)autoindex_localtime [on|off] 開啓本地時間顯示檔案時間}

(09)【瀏覽器本地快取】:expires [time|epoch|max|off]time 時間值 負數不快取epoch 設定爲1 january,1970, 00:00:01 GMTmax 設定爲 31 December 2037 23:59:59 GMT

(10)【php fastcgi】:location ~ $ {fastcgi_pass   ;fastcgi_index  ;fastcgi_param  SCRIPT_FILENAME $document_root/$fastcgi_script_name;include        fastcgi_params;}