我紅帽上的nginx配置
來源:互聯網
上載者:User
user nobody nobody;
#啟動進程
worker_processes 2;
#全域錯誤記錄檔及PID檔案
error_log /var/log/nginx/error.log notice;
pid /var/log/nginx.pid;
#工作模式及串連數上限
events {
use epoll;
worker_connections 1024;
}
#設定http伺服器,利用它的反向 Proxy功能提供負載平衡支援
http {
#設定mime類型
include /etc/nginx/mime.types;
default_type application/octet-stream;
#設定日誌格式
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';
log_format download '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$http_range" "$sent_http_content_range"';
#設定請求緩衝
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
#開啟gzip模組
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;
output_buffers 1 32k;
postpone_output 1460;
#設定access log
access_log /var/log/nginx/access.log main;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
#設定負載平衡的伺服器列表
upstream mysvr {
#weigth參數表示權值,權值越高被分配到的幾率越大
#本機上的Squid開啟3128連接埠
server 192.168.0.1:80 weight=1;
}
#設定虛擬機器主機
server {
listen 80;
server_name 192.168.0.71
;
charset gb2312;
#設定本虛擬機器主機的訪問日誌
access_log /var/log/nginx/access.log main;
#如果訪問 /img/*, /js/*, /css/* 資源,則直接取本地檔案,不通過squid
#如果這些檔案較多,不推薦這種方式,因為通過squid的緩衝效果更好
location ~ ^/(img|js|css)/ {
root /data3/Html;
expires 24h;
}
#對 "/" 啟用負載平衡
location / {
proxy_pass http://mysvr;
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;
}
}
}