2017-10-06 63 views
0

我在尋找與重定向解決另一個域,如果從HTTP服務器的響應是404404重定向到另一臺服務器/域

acl not_found status 404 
acl found_ceph status 200 
use_backend minio_s3 rsprep ^HTTP/1.1\ 404\ (.*)$ HTTP/1.1\ 302\ Found\nLocation:\/if not_found 
use_backend ceph if found_ceph 

但仍然沒有工作,這個規則去minio_s3後端。

謝謝你的建議。

回答

0

當來自後端的響應具有狀態404時,首先添加一個Location標頭,該標頭將原始URI完整地發送到example.com,然後將狀態碼設置爲302,以便瀏覽器執行重定向。

backend my-backend 
    mode http 
    server my-server 203.0.113.113:80 check inter 60000 rise 1 fall 2 
    http-response set-header Location http://example.com%[capture.req.uri] if { status eq 404 } 
    http-response set-status 302 if { status eq 404 } 

測試:

$ curl -v http://example.org/pics/funny/cat.jpg 
* Hostname was NOT found in DNS cache 
* Trying 127.0.0.1... 
* Connected to example.org (127.0.0.1) port 80 (#0) 
> GET /pics/funny/cat.jpg HTTP/1.1 
> User-Agent: curl/7.35.0 
> Host: example.org 
> Accept: */* 

實際後端返回404,但我們沒有看到它。相反...

< HTTP/1.1 302 Moved Temporarily 
< Last-Modified: Thu, 04 Aug 2016 16:59:51 GMT 
< Content-Type: text/html 
< Content-Length: 332 
< Date: Sat, 07 Oct 2017 00:03:22 GMT 
< Location: http://example.com/pics/funny/cat.jpg 

從後端的404錯誤頁面的響應體將仍然被髮送到瀏覽器,但是 - 事實證明 - 瀏覽器不會顯示出來,所以又何妨呢。這需要HAProxy 1.6或更高版本。

相關問題