1. 程式人生 > >nginx配置多端口轉發

nginx配置多端口轉發

nginx

[root@iscsid conf]# cat nginx.conf
user nginx nginx;
worker_processes 8;

error_log /opt/nginx/logs/nginx_error.log crit;
pid /opt/nginx/logs/nginx.pid;

worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}

http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;

sendfile on;
tcp_nopush on;
keepalive_timeout 60;

tcp_nodelay on;
gzip on;
#gzip_min_length 1k;
#gzip_buffers 4 16k;
#gzip_http_version 1.0;
#gzip_comp_level 2;
#gzip_types text/plain application/x-javascript text/css application/xml;

#gzip_vary on;
upstream web.abc.com {
ip_hash;
server 192.168.5.91:8382;
server 192.168.5.91:8383;
server 192.168.5.91:8384;
server 192.168.5.91:8385;
}
server
{
listen 8181;
server_name localhost;
proxy_redirect off;

   #後端的Web服務器可以通過X-Forwarded-For獲取用戶真實IP
   proxy_set_header   X-Forwarded-For  $remote_addr;

if ($request_uri ~ "..(js|css|gif|jpg|jpeg|png|bmp|swf)$")

{

proxy_pass http://squid.abc.com;

}

if ($request_uri ~ "^/view/(.)$")

{

proxy_pass http://squid.abc.com;

}

proxy_pass http://web.abc.com;

  location /chinawidth {
       #alias  html/;
       proxy_pass http://web.abc.com;
       index  index.html index.htm index.jpg index.pwp;
   }
  location /iflashbuy {
       #alias  html/;
       proxy_pass http://web.abc.com;
       index  index.html index.htm index.jpg index.pwp;
   }

#定義日誌格式

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  /opt/nginx/logs/access.log  access;

#允許客戶端請求的最大的單個文件字節數
client_max_body_size 10m;

   #緩沖區代理緩沖用戶端請求的最大字節數 可以理解為先保存到本地再傳給用戶
   client_body_buffer_size  128k;

   #跟後端服務器連接的超時時間_發起握手等候響應超時時間
   proxy_connect_timeout    600;

   #連接成功後_等候後端服務器響應時間_其實已經進入後端的排隊之中等候處理
   proxy_read_timeout       600;

   #後端服務器數據回傳時間_就是在規定時間之內後端服務器必須傳完所有的數據
   proxy_send_timeout       600;

#代理請求緩存區_這個緩存區間會保存用戶的頭信息以供Nginx進行規則處理_一般只要能保存下頭信息即可
proxy_buffer_size 8k;

   #同上 告訴Nginx保存單個用的幾個Buffer 最大用多大空間
   proxy_buffers            4 32k;

   #如果系統很忙的時候可以申請更大的proxy_buffers 官方推薦*2    
   proxy_busy_buffers_size 64k;

   #proxy緩存臨時文件的大小
   proxy_temp_file_write_size 64k;

}
}

nginx配置多端口轉發