haproxy 上的反向代理设置给出 500;基本服务器上的 wget & nginx 工作

Reverse proxy setup on haproxy gives 500; wget on base server & nginx works

我正在尝试将 haproxy 设置为服务器的反向代理。我在 Centos.

配置如下:

global
   #log /dev/log local0
   #log /dev/log local1 notice
   log 127.0.0.1 local2 info
   log 127.0.0.1 local2 notice
   log 127.0.0.1 local2 debug
   chroot /var/lib/haproxy
   stats timeout 30s
   user haproxy
   group haproxy
   daemon

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

frontend http_front
   bind *:801
   option forwardfor
   stats enable
   default_backend http_back

backend http_back
   mode http
   option httpchk
   option forwardfor
   http-send-name-header Host
   balance roundrobin
   server server1 stg-hostserv.com:80

但是,如果我针对它执行 wget,则会出现以下错误。

# wget http://0.0.0.0:801
--2018-07-16 14:26:24--  http://0.0.0.0:801/
Connecting to 0.0.0.0:801... connected.
HTTP request sent, awaiting response... 500 Internal Server Error
2018-07-16 14:26:24 ERROR 500: Internal Server Error.


     haproxy  -f /etc/haproxy/haproxy.cfg -d
[WARNING] 197/200148 (13833) : config : frontend 'GLOBAL' has no 'bind' directive. Please declare it as a backend if this was intended.
Available polling systems :
      epoll : pref=300,  test result OK
       poll : pref=200,  test result OK
     select : pref=150,  test result FAILED
Total: 3 (2 usable), will use epoll.
Using epoll() as the polling mechanism.
00000000:http_front.accept(0004)=0006 from [127.0.0.1:60696]
00000000:http_front.clireq[0006:ffffffff]: GET / HTTP/1.1
00000000:http_front.clihdr[0006:ffffffff]: User-Agent: Wget/1.14 (linux-gnu)
00000000:http_front.clihdr[0006:ffffffff]: Accept: */*
00000000:http_front.clihdr[0006:ffffffff]: Host: 0.0.0.0:801
00000000:http_front.clihdr[0006:ffffffff]: Connection: Keep-Alive
00000000:http_back.srvrep[0006:0007]: HTTP/1.1 500 Internal Server Error
00000000:http_back.srvhdr[0006:0007]: Content-Type: text/html
00000000:http_back.srvhdr[0006:0007]: Server: Microsoft-IIS/8.0
00000000:http_back.srvhdr[0006:0007]: X-Powered-By: ASP.NET
00000000:http_back.srvhdr[0006:0007]: Date: Tue, 17 Jul 2018 12:02:00 GMT
00000000:http_back.srvhdr[0006:0007]: Connection: close
00000000:http_back.srvhdr[0006:0007]: Content-Length: 1208
00000001:http_front.clicls[0006:ffffffff]
00000001:http_front.closed[0006:ffffffff]
^C
[root@izp0w3tkx2yr8zhes26ajqz ~]#

我为服务器尝试了不同的配置,但始终遇到 500 错误。 Wget 到基本服务器工作没有任何问题。 我将 nginix 设置为相同的东西并且它工作得很好。只是 haproxy 似乎不起作用。客户希望它在 haproxy 上。 :)

你能告诉我在哪里可以进一步调试吗?感谢您的协助。

来自 nuster 缓存服务器的此更新帮助解决了问题:

Does your backend Microsoft-IIS/8.0 check host header? as you set http-send-name-header Host, so request from HAProxy to stg-hostserv.com:80 looks like GET / HTTP/1.1 Host: izp0w3tkx2yr8zhes26ajqz

HAProxy 在我设置时工作:

http-request set-header Host stg-hostserv.com