天天看點

一次反向代理負載均衡的處理過程

一、現象: 

a.b.c.d - - [07/Jan/2017:04:21:45 +0000] "GET /cxf/sps-9cd4b47f-1c95-4f08-bf29-e536b9540a4a&pl6c378605000152&actionid=58706981d3 HTTP/1.1" 405 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"

405 Method Not Allowed:請求方法(GET、POST、HEAD、DELETE、PUT、TRACE等)對指定的資源不适用。

根本原因是自己用curl測試的時候預設使用的是get方法,我們需要用post方法:

a.b.c.d - - [07/Jan/2017:04:21:53 +0000] "GET /cxf/spin/rest/get6cc HTTP/1.1" 404 47 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"

為什麼會出現404呢?就是因為請求沒有擷取到資源。這個由于自己的haproxy配置出錯:

frontend  main *:6443

  #acl url_external       path_beg       -i /aeostervice

  acl url_external       path_beg       -i /xf/sin/rest/

我們需要把/aeostervice改成/xf/sin/rest/

karaf簡介:

<a href="http://wenku.baidu.com/link?url=y_SCAhXFtNgsjcoHrfCka36ygqeV-DUGlfZ-Q0RSRK5qRsRJt310zFEHjX0ullMCRJqRxWDD_p4bIFyxn4Af-pRlW2oWYELU5686SmFvflq" target="_blank">http://wenku.baidu.com/link?url=y_SCAhXFtNgsjcoHrfCka36ygqeV-DUGlfZ-Q0RSRK5qRsRJt310zFEHjX0ullMCRJqRxWDD_p4bIFyxn4Af-pRlW2oWYELU5686SmFvflq</a>

二、haproxy 逾時機制

timeout http request :在用戶端建立連接配接但不請求資料時,關閉用戶端連接配接  

timeout queue :等待最大時長  

timeout connect: 定義haproxy将用戶端請求轉發至後端伺服器所等待的逾時時長  

timeout client:用戶端非活動狀态的逾時時長  

timeout server:用戶端與伺服器端建立連接配接後,等待伺服器端的逾時時長,  

timeout http-keep-alive :定義保持連接配接的逾時時長  

timeout check:健康狀态監測時的逾時時間,過短會誤判,過長資源消耗  

client_timeout 是 app 連接配接 haproxy的時間  

server_timeout 是haproxy 連接配接後端的時間.  

下面是我們自己的伺服器配置:

defaults

    mode                    http

    log                     global

    option                  httplog

    option                  dontlognull

    option http-server-close

    option forwardfor       except 127.0.0.0/8

    option                  redispatch

    retries                 3

    timeout http-request    10s注意:如果這裡沒有機關預設是毫秒

    timeout queue           1m

    timeout connect         10s

    timeout client          1m

    timeout server          1m

    timeout http-keep-alive 10s

    timeout check           10s

    maxconn                 3000

本文轉自chenzudao51CTO部落格,原文連結: http://blog.51cto.com/victor2016/1890001,如需轉載請自行聯系原作者