這篇文章主要介紹了關於Nginx設定檔nginx.conf解讀,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下
開啟一個全新配置的nginx的nginx.conf檔案,檔案結構大概是這個樣子:
#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; #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; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #}}
一大堆代碼看起來眼花繚亂,其實並不複雜,我們來看精簡版的:
# 全域區worker_processes 1; # 有1個工作的worker子進程#可以自行修改,但太大會造成相互爭奪CPU,一般來說:子進程數 = CPU數 * 核心數# 配置nginx的串連特性events { worker_connections 1024; # 1個worker子進程能同時允許的最大串連數}# http伺服器主要段http { # 設定mime類型,類型由mime.types檔案定義 include mime.types; default_type application/octet-stream; sendfile on; # 是否調用sendfile來輸出檔案 keepalive_timeout 65; # 連線逾時時間 # 虛擬機器主機段 server { listen 80; # 監聽連接埠 server_name localhost; # 監聽主機\網域名稱\連接埠 # 定義訪問響應 location / { root html; # 根目錄定位 index index.html index.htm; # 預設訪問頁面定位 } # 定義錯誤提示頁面 location = /50x.html { root html; }}