網站首頁 健康小知識 母嬰教育 起名 運動知識 職場理財 情感生活 綠色生活 遊戲數碼 美容 特色美食 愛好
當前位置:酷知知識幫 > 遊戲數碼 > 電腦

nginx 配置詳解

欄目: 電腦 / 發佈於: / 人氣:1.54W

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;}