nginx設定檔詳細教程,nginx設定檔
nginx設定檔詳細教程
Nginx設定檔位於nginx目錄下的conf檔案夾下,為nginx.conf,下面簡單介紹下設定檔中各項的含義,一入nginx深似海,功能非常強大,同時也非常複雜。
全域配置:
user nobody; #運行使用者worker_processes 1; #表示背景工作處理序的數量,通常設定成和CPU的數量相等全域錯誤記錄檔以及pid檔案#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;
Events模組:
events { worker_connections 1024; #單個後台worker process進程的最大並發串連數}
http模組:
http { include mime.types; #設定mime類型,類型由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; #指令指定nginx是否調用sendfile函數來輸出檔案 #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #連線逾時時間 #gzip on; #開啟gzip壓縮 autoindex on; #設定顯示項目目錄 #設定虛擬機器主機配置 server { listen 80; #監聽80連接埠 server_name demo.shop.cn; #設定訪問網域名稱 root html; #定義伺服器的預設項目根目錄 #charset koi8-r; #access_log logs/host.access.log main; #設定本虛擬機器主機的預設訪問日誌 #預設請求 location / { root html; index index.php 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; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass https://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 #PHP指令碼請求全部轉寄到FastCGI處理,使用FastCGI預設配置 location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$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; #} }