0

I am trying to setup haproxy as a reverse proxy for a server. I am on Centos.

The config goes like this:

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

But, if I do a wget against it, I am getting the below error.

# 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 ~]#

I tried different config for the server and consistently hit 500 error. Wget to the base server works without any issues. I setup nginix to the same thing and it works beautifully. Just haproxy does not seem to work. The customer wants it on haproxy. :)

Can you please advise where I can look at to further debug. Appreciate your assistance.

Prak_Rum
  • 25
  • 1
  • 11
  • You're not showing us logs or configuration that appear to match the test you claim to be making. Where does the double `//` in `GET //app_themes/base...` come from? What's in the HAProxy log and the back-end log? – Michael - sqlbot Jul 16 '18 at 10:40
  • Sorry. My bad. I did a few tests and must have mixed up the logs. Here are the matching ones. – Prak_Rum Jul 17 '18 at 12:02
  • 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` – nuster cache server Jul 19 '18 at 01:01
  • Hi, Thanks for the response. That option is one of the last that I added. Even without that option, I got the same error. – Prak_Rum Jul 19 '18 at 03:16
  • Can you check `curl http://stg-hostserv.com:80/ -H "Host: izp0w3tkx2yr8zhes26ajqz"` ? – nuster cache server Jul 20 '18 at 00:43
  • Wow!! I got the same error.

    500 - Internal server error.

    There is a problem with the resource you are looking for, and it cannot be displayed.

    – Prak_Rum Jul 20 '18 at 01:52
  • I tried changing the hostname and it did not fix. :( http-send-name-header stg-hostserv.com – Prak_Rum Jul 20 '18 at 05:03
  • curl -v http://stg-hostserv.com/ -H "Host: stg-hostserv.com" #Works curl -v http://stg-hostserv.com/ -H "Host: dummy" #Does not Work curl -v http://0.0.0.0:801/ -H "Host: stg-hostserv.com" #HAproxy endpoint Does not Work with correct hostname :( – Prak_Rum Jul 20 '18 at 05:20
  • If I change it to the below and pass the header as parameter it works.. curl -v http://0.0.0.0:801/ -H "Host: stg-hostserv.com" http-request set-header X-Forwarded-Host %[req.hdr(Host)] Anyway I can avoid passing the host name and set it in the config? Please advise. – Prak_Rum Jul 20 '18 at 05:31
  • It worked when I set it up like this. http-request set-header Host stg-hostserv.com Thanks a ton guys. You are great. – Prak_Rum Jul 20 '18 at 05:36

1 Answers1

0

This update from nuster cache server helped solve the problem:

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 worked when I set:

http-request set-header Host stg-hostserv.com
Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Prak_Rum
  • 25
  • 1
  • 11