user www www;#使用哪個用戶啓動nginx 前面是用戶,後面是組
worker_processes 4;#nginx工作的進程數量
worker_processes 4;#nginx工作的進程數量
#[ debug | info | notice | warn | error | crit ] 錯誤日誌的級別及位置
error_log /var/htdocs/logs/nginx_error.log crit;
error_log /var/htdocs/logs/nginx_error.log crit;
pid /usr/local/nginx/nginx.pid;#進程文件
worker_rlimit_nofile 51200;#一個nginx進程打開的最多文件描述符數目,理論值應該是最多打開文件數(ulimit -n)與nginx進程數相除,但是nginx分配請求並不是那麼均勻,所以最好與ulimit -n的值保持一致。
worker_rlimit_nofile 51200;#一個nginx進程打開的最多文件描述符數目,理論值應該是最多打開文件數(ulimit -n)與nginx進程數相除,但是nginx分配請求並不是那麼均勻,所以最好與ulimit -n的值保持一致。
#工作模式及連接數上限
events
{
# use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];
use epoll; #使用epoll(linux2.6的高性能方式)
worker_connections 51200; #每個進程最大連接數(最大連接=連接數x進程數)
}
events
{
# use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];
use epoll; #使用epoll(linux2.6的高性能方式)
worker_connections 51200; #每個進程最大連接數(最大連接=連接數x進程數)
}
#設定http服務器
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"’;
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"’;
log_format download ‘$remote_addr – $remote_user [$time_local] ‘
‘"$request" $status $bytes_sent ‘
‘"$http_referer" "$http_user_agent" ‘
‘"$http_range" "$sent_http_content_range"’;
‘"$request" $status $bytes_sent ‘
‘"$http_referer" "$http_user_agent" ‘
‘"$http_range" "$sent_http_content_range"’;
charset gb2312,utf-8;#默認編碼
server_names_hash_bucket_size 128;#服務器名字的hash表大小
sendfile on; #開啓高效文件傳輸模式
#以下兩個選項用於防止網絡阻塞
tcp_nopush on;
tcp_nodelay on;
server_names_hash_bucket_size 128;#服務器名字的hash表大小
sendfile on; #開啓高效文件傳輸模式
#以下兩個選項用於防止網絡阻塞
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 300; #超時時間
#FastCGI是爲了改善網站的性能--減少資源佔用,提高訪問速度.有關fastCGI的詳細資料請參閱:http://www.fastcgi.com
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_temp_path /dev/shm;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_temp_path /dev/shm;
gzip on; #打開gzip壓縮
gzip_min_length 1k; #最小壓縮文件大小
gzip_buffers 4 8k; #壓縮緩衝區
gzip_http_version 1.1; #壓縮版本(默認1.1,前端爲squid2.5使用1.0)
#壓縮類型,默認就已經包含text/html 所以下面就不用再寫了,當然寫上去的話,也不會有問題,但是會有一個warn
gzip_types text/plain application/x-javascript text/css text/html text/javascript application/xml;
#錯誤頁面
error_page 404 http://www.freeopens.com;
error_page 403 http://www.freeopens.com;
gzip_min_length 1k; #最小壓縮文件大小
gzip_buffers 4 8k; #壓縮緩衝區
gzip_http_version 1.1; #壓縮版本(默認1.1,前端爲squid2.5使用1.0)
#壓縮類型,默認就已經包含text/html 所以下面就不用再寫了,當然寫上去的話,也不會有問題,但是會有一個warn
gzip_types text/plain application/x-javascript text/css text/html text/javascript application/xml;
#錯誤頁面
error_page 404 http://www.freeopens.com;
error_page 403 http://www.freeopens.com;
client_max_body_size 20m; #上傳文件大小限制
#設定請求緩
client_header_buffer_size 16k;
large_client_header_buffers 4 64k;
#設定負載均衡的服務器列表
#如果在同一臺機器上,單獨起4組獨立的php-cgi進程(每組8個子進程),性能應該不如1組php-cgi進程(32個子進程),因爲1組進程,eaccelerator的PHP二進制文件緩存是共享的,1組進程命中率較高。
#不過好處是,碰到某組的php假死的話,其他端口就可以接管了,我實測下來似乎發生502錯誤的概率降低了很多,或者說我這樣配置以後還沒有遇到
upstream mysvr {
#weigth參數表示權值,權值越高被分配到的機率越大
#本機上的Squid開啓3128端口
server 192.168.8.1:3128 weight=5;
server 192.168.8.2:80 weight=1;
server 192.168.8.3:80 weight=6;
}
#虛擬主機的配置
server
{
listen 80;
server_name www.freeopens.com;
index index.html Index.html index.htm index.php;
root /var/htdocs/freeopens;
if (-d $request_filename)
{
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}
#設定本虛擬主機的訪問日誌
access_log logs/www.freeopens.com.access.log main;
#設定請求緩
client_header_buffer_size 16k;
large_client_header_buffers 4 64k;
#設定負載均衡的服務器列表
#如果在同一臺機器上,單獨起4組獨立的php-cgi進程(每組8個子進程),性能應該不如1組php-cgi進程(32個子進程),因爲1組進程,eaccelerator的PHP二進制文件緩存是共享的,1組進程命中率較高。
#不過好處是,碰到某組的php假死的話,其他端口就可以接管了,我實測下來似乎發生502錯誤的概率降低了很多,或者說我這樣配置以後還沒有遇到
upstream mysvr {
#weigth參數表示權值,權值越高被分配到的機率越大
#本機上的Squid開啓3128端口
server 192.168.8.1:3128 weight=5;
server 192.168.8.2:80 weight=1;
server 192.168.8.3:80 weight=6;
}
#虛擬主機的配置
server
{
listen 80;
server_name www.freeopens.com;
index index.html Index.html index.htm index.php;
root /var/htdocs/freeopens;
if (-d $request_filename)
{
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}
#設定本虛擬主機的訪問日誌
access_log logs/www.freeopens.com.access.log main;
location ~ .*\.php?$
{
include fcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
#如果訪問 /img/*, /js/*, /css/* 資源,則直接取本地文件,不通過squid
#如果這些文件較多,不推薦這種方式,因爲通過squid的緩存效果更好
location ~ ^/(img|js|css)/ {
root /var/htdocs/freeopens;
expires 24h;
}
{
include fcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
#如果訪問 /img/*, /js/*, /css/* 資源,則直接取本地文件,不通過squid
#如果這些文件較多,不推薦這種方式,因爲通過squid的緩存效果更好
location ~ ^/(img|js|css)/ {
root /var/htdocs/freeopens;
expires 24h;
}
#對 "/" 啓用負載均衡
location / {
proxy_pass http://127.0.0.1;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
location / {
proxy_pass http://127.0.0.1;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
#設定查看Nginx狀態的地址
location /NginxStatus {
stub_status on;
access_log on;
auth_basic "NginxStatus";
auth_basic_user_file conf/htpasswd;
}
location /NginxStatus {
stub_status on;
access_log on;
auth_basic "NginxStatus";
auth_basic_user_file conf/htpasswd;
}