1. 程式人生 > >Nginx配置檔案詳解說明

Nginx配置檔案詳解說明


#啟動子程序程式預設使用者
#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伺服器設定 http { #設定mime型別,型別由mime.type檔案定義 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"';
#$remote_addr與$http_x_forwarded_for用以記錄客戶端的ip地址; #$remote_user:用來記錄客戶端使用者名稱稱; #$time_local: 用來記錄訪問時間與時區; #$request: 用來記錄請求的url與http協議; #$status: 用來記錄請求狀態;成功是200, #$body_bytes_sent :記錄傳送給客戶端檔案主體內容大小; #$http_referer:用來記錄從那個頁面連結訪問過來的; #$http_user_agent:記錄客戶瀏覽器的相關資訊; #全域性訪問日誌路徑
#access_log logs/access.log main; #sendfile指令指定 nginx 是否呼叫sendfile 函式(zero copy 方式)來輸出檔案,對於普通應用,必須設為on。如果用來進行下載等應用磁碟IO重負載應用,可設定為off,以平衡磁碟與網路IO處理速度,降低系統uptime。 sendfile on; #此選項允許或禁止使用socke的TCP_CORK的選項,此選項僅在使用sendfile的時候使用 #tcp_nopush on; #長連線超時時間 #keepalive_timeout 0; keepalive_timeout 65; #開啟壓縮 #gzip on; #配置虛擬主機 一個server一個網站 server { #虛擬主機使用的埠 listen 80; #虛擬主機域名 server_name localhost; #虛擬主機支援的字符集 #charset koi8-r; #虛擬主機的訪問日誌路徑 #access_log logs/host.access.log main; #定義web根路徑 location / { #根目錄路徑 root html; #索引頁 index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # #根據錯誤碼 返回對應的頁面 error_page 500 502 503 504 /50x.html; #定義頁面路徑 location = /50x.html { root html; } #定義反向代理伺服器 資料伺服器是lamp模型 # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} #定義PHP為本機服務的模型 # 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 # #拒絕apache DR目錄及子目錄下的.htaccess檔案訪問 #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} #https的配置方案 # 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; # } #} }