nginx配置練習

feiwu1hao發表於2021-02-27

檔案配置結構

main
events {}
http {
  server {
  location {}
  }
}

執行順序從外到內

nginx配置練習

栗子

worker_process 1; //worker程式數目
events {
  worker_connections 1024; //w單個orker可同時處理的連線數目
}
http {
  include mine.type; //以相對路徑引入新的配置檔案, 預設字首為/usr/local/nginx/conf
  default_type application/octet-stream;
  sendfile on;
  keepalive_timeout 65;
  server {
  listen 80;
  server_name localhost;
  location / {
      root html;
      index index.htm, index.html;
  }
  error_page 500 502 503 504 /50x.html;
  location=/50x.html {
      root html;
  }
  }
}

指令配置最佳實踐

指令 說明
worker_ processes 配置nginx的工作程式數,一般設定為cpu總核數或者為auto
work_connections nginx單個程式併發連線最大請求,一般設定為1024
include 引入配置檔案,可以使用相對路徑或者絕對路徑
default_type 設定返回的檔案型別格式
sendfile 預設為on, 表示
keepalive_timeout 設定長連線超時時間
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章