Nginx實用指南V1(連載之二:Nginx配置檔案詳解)

科技小先鋒發表於2017-11-17

user  www www;  

#定義Nginx執行的使用者及組

worker_processes 8; 

#程式數,一般是配置為小於CPU數。

#[ debug | info | notice | warn | error | crit ]

error_log  /data1/logs/nginx_error.log  crit; 

#錯誤日誌定義型別

pid        /usr/local/webserver/nginx/nginx.pid; 

#程式檔案

#Specifies the value for maximum file descriptors that can be opened by this process. 

worker_rlimit_nofile 65535;

#一個nginx程式開啟的最多檔案描述符數目,理論值應該是最多開啟檔案數(ulimit -n)與nginx程式數相除,但是nginx分配請求並不是那麼均勻,所以最好與ulimit -n的值保持一致。

# use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; 

events 

{

use epoll;   #參考事件模型

worker_connections 65535; #每個程式最大連線數(最大連線=連線數x程式數) 

}

#設定http伺服器 

http 

{

include       mime.types;  #副檔名與檔案型別對映表

default_type  application/octet-stream; #預設檔案型別 

#charset  gb2312;  #預設編碼 

server_names_hash_bucket_size 128; #伺服器名字的hash表大小

client_header_buffer_size 32k;  #上傳檔案大小限制 

large_client_header_buffers 4 32k;  #設定請求緩 

client_max_body_size 8m;  #設定請求緩 

sendfile on; #開啟高效檔案傳輸模式 

tcp_nopush     on;  #防止網路阻塞 

tcp_nodelay on;  #防止網路阻塞

keepalive_timeout 60;  #超時時間


#FastCGI是為了改善網站的效能--減少資源佔用,提高訪問速度.有關fastCGI的詳細資料請參閱:http://www.fastcgi.com 

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

fastcgi_buffer_size 64k;

fastcgi_buffers 4 64k;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 128k;

gzip on;

gzip_min_length  1k;  #最小壓縮檔案大小 

gzip_buffers     4 16k;   #壓縮緩衝區 

gzip_http_version 1.0;    #壓縮版本(預設1.1,前端為squid2.5使用1.0

gzip_comp_level 2;  #壓縮等級

gzip_types       text/plain application/x-javascript text/css application/xml;

#壓縮型別,預設就已經包含text/html 所以下面就不用再寫了,當然寫上去的話,也不會有問題,但是會有一個warn 

gzip_vary on;  

#limit_zone  crawler  $binary_remote_addr  10m;  #開啟限制IP連線數的時候需要使用

#虛擬主機的配置

server

{

listen       80;

server_name  www.opendoc.com.cn

index index.html index.htm index.php;

root  /data0/htdocs/opendoc;                     

location ~ .*.(php|php5)?$

{      

#fastcgi_pass  unix:/tmp/php-cgi.sock;

fastcgi_pass  127.0.0.1:9000;

fastcgi_index index.php;

include fcgi.conf;

}

#對圖片快取

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$

{

expires      30d;

}

#對JS CSS 快取

location ~ .*.(js|css)?$

{

expires      1h;

}    

#日誌設定

log_format  access  `$remote_addr – $remote_user [$time_local] “$request” `

`$status $body_bytes_sent “$http_referer” `

`”$http_user_agent” $http_x_forwarded_for`;

access_log  /data1/logs/access.log  access;

}

}

本文轉自守住每一天51CTO部落格,原文連結:http://blog.51cto.com/liuyu/294118,如需轉載請自行聯絡原作者


相關文章