#運作使用者
#user nobody;
#啟動程序,通常設定成和cpu的數量相等
worker_processes 1;
#全局錯誤日志檔案
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
# PID檔案
#pid logs/nginx.pid;
events{
#epoll是多路複用IO(I/O Multiplexing)中的一種方式,但是僅用于linux2.6以上核心,可以大大提高nginx的性能
use epoll;
#單個背景worker process程序的最大并發連結數
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"';
#access_log logs/access.log main;
#sendfile指令指定nginx是否調用sendfile函數(zero copy方式)來輸出檔案,對于普通應用,必須設為 on,如果用來進行下載下傳等應用磁盤IO重負載應用,可設定為off,以平衡磁盤與網絡I/O處理速度,降低系統的uptime.
sendfile on;
#tcp_nopush on;
#連接配接逾時時間
#keepalive_timeout 0;
keepalive_timeout 65;
#開啟gzip壓縮
#gzip on;
#設定請求緩沖
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
#設定負載均衡的伺服器清單
upstream mysvr{
#weigth參數表示權值,權值越高被配置設定到的幾率越大
server 192.168.8.1:3128 weight=5; #本機上的Squid開啟3128端口
server 192.168.8.2:80 weight=1;
server 192.168.8.3:80 weight=6;
}
server{
listen 80; #偵聽80端口
server_name www.xx.com; #定義使用www.xx.com通路
#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
#
error_page 500 502 503 504 /50x.html; #定義錯誤提示頁面
location = /50x.html {
root html;
}
#靜态檔案,nginx自己處理
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
root /var/www/virtual/htdocs;
#過期30天,靜态檔案不怎麼更新,過期可以設大一點,如果頻繁更新,則可以設定得小一點。
expires 30d;
}
# 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
#PHP腳本請求全部轉發到 FastCGI處理. 使用FastCGI預設配置.
#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;
#}
location ~.*\.aspx${#對aspx字尾的進行負載均衡請求
root /root; #定義伺服器的預設網站根目錄位置
index index.php index.htmlindex.htm; #定義首頁索引檔案的名稱
proxy_pass http://mysvr ;#請求轉向mysvr 定義的伺服器清單
#以下是一些反向代理的配置可删除.
proxy_redirect off;
#後端的Web伺服器可以通過X-Forwarded-For擷取使用者真實IP
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_size128k; #緩沖區代理緩沖使用者端請求的最大位元組數
proxy_connect_timeout 90; #nginx跟後端伺服器連接配接逾時時間(代理連接配接逾時)
proxy_send_timeout 90; #後端伺服器資料回傳時間(代理發送逾時)
proxy_read_timeout 90; #連接配接成功後,後端伺服器響應時間(代理接收逾時)
proxy_buffer_size 4k; #設定代理伺服器(nginx)儲存使用者頭資訊的緩沖區大小
proxy_buffers 4 32k; #proxy_buffers緩沖區
proxy_busy_buffers_size64k; #高負荷下緩沖大小(proxy_buffers*2)
proxy_temp_file_write_size64k; #設定緩存檔案夾大小,大于這個值,将從upstream伺服器傳
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#禁止通路 .ht檔案
#location ~ /\.ht {
# deny all;
#}
location /NginxStatus {#設定檢視Nginx狀态的位址
stub_status on;
access_log on;
auth_basic "NginxStatus";
auth_basic_user_file conf/htpasswd;
}
}
}
熬夜不易,點選請老王喝杯烈酒!!!!!!!