訪問proxy.xxxx.com ,顯示 https://192.168.1.60 內(nèi)容蘸劈,實現(xiàn)負(fù)載均衡,在nginx配置文件夾里增加 /usr/local/nginx/conf/proxy.xxxx.com.conf 文件碾阁,內(nèi)容如下:
server
{
? ? listen 80;
? ? server_name proxy.xxxx.com;
? ? #設(shè)定負(fù)載均衡的服務(wù)器列表
? ? #這樣weight=3表示3/6的幾率訪問第一個server,1/6訪問第二個痰滋。另外還可以定義max_fails和fail_timeout等參數(shù)。
? ? upstream hello{
? ? ? ? server 192.168.1.60:1985 weight=3 max_fails=2 fail_timeout=30s;
? ? ? ? server 192.168.1.42:8086 weight=1 max_fails=2 fail_timeout=30s;
? ? }
? ? location / {
? ? ? ? proxy_pass? http://hello;? ? #在這里設(shè)置一個代理站刑,和upstream的名字一樣
? ? ? ? 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;
? ? }
? ? access_log logs/proxy.xxxx.com_access.log;
}
可以參考:http://blog.csdn.net/hiyun9/article/details/51602428
Nginx解決轉(zhuǎn)發(fā)地址時跨域的問題另伍,增加以下代碼:
#add_header Access-Control-Allow-Origin *;
#add_header Access-Control-Allow-Methods "POST, GET, OPTIONS";
#add_header Access-Control-Allow-Headers "Origin, Authorization, Accept";
#add_header Access-Control-Allow-Credentials true;
nginx 反向代理參數(shù)說明:
proxy_temp_path /home/proxy_temp_dir; #指定臨時文件目錄
proxy_cache_path /home/proxy_cache_dir levels=1:2 keys_zone=cache_one:50m inactive=1d max_size=1g;
#設(shè)置Web緩存區(qū)名稱為cache_one,內(nèi)存緩存為50MB绞旅,自動清除1天內(nèi)沒有被訪問的文件摆尝,硬盤緩存為1GB。
client_body_buffer_size 512k; #增加緩沖區(qū)代理緩沖客戶端請求的最大字節(jié)數(shù)
proxy_connect_timeout 60; #增加連接后端服務(wù)器超時時間(代理連接超時)
proxy_read_timeout 60; #增加后端服務(wù)器響應(yīng)請求超時時間(代理接收超時)
proxy_send_timeout 60; #增加后端服務(wù)器發(fā)送數(shù)據(jù)超時時間(代理發(fā)送超時)
proxy_buffer_size 32k; #設(shè)置代理服務(wù)器(nginx)保存用戶頭信息的緩沖區(qū)大小
proxy_buffers 4 64k; #proxy_buffers緩沖區(qū)因悲,網(wǎng)頁平均在32k以下的話堕汞,這樣設(shè)置
proxy_busy_buffers_size 128k; #增加高負(fù)荷下緩沖大小或者系統(tǒng)繁忙時可申請的proxy_buffers大小(proxy_buffers*2)
proxy_temp_file_write_size 128k; #增加proxy緩存臨時文件的大小
proxy_cache_key $host$uri$is_args$args; #增加設(shè)置web緩存的key值晃琳,nginx根據(jù)key值md5哈希存儲緩存
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; #增加故障轉(zhuǎn)移讯检,如果后端的服務(wù)器返回502、504卫旱、執(zhí)行超時等錯誤人灼,自動將請求轉(zhuǎn)發(fā)到upstream負(fù)載均衡池中的另一臺服務(wù)器,實現(xiàn)故障轉(zhuǎn)移顾翼。proxy_cache cache_one; #增加使用web緩存區(qū)cache_one