Fateme Ghasemi
Fateme Ghasemi

Reputation: 285

Getting 404 when call request by haproxy (directly works fine)

I directly call a web service with url curl http://venesh.ir/webservice/oauth/token and I got error 403, but when I call it by reverse proxy from some server I got 404,is it possible that haproxy change my address?

haproxy config:

frontend localhost
    bind *:8081
    option tcplog
    mode tcp
    acl isVenesh dst_port 8081
    use_backend venesh if isVenesh
    default_backend venesh


backend venesh
    mode tcp
    balance roundrobin
    server web01 venesh.ir:80 check

when I call mySerevrIp:8081/webservice/oauth/token I expect getting the result that I directly call curl http://venesh.ir/webservice/oauth/token that is 403,

but when I call curl mySerevrIp:8081/webservice/oauth/token I get error 404,

Is a problem with my haproxy or my config or is it possible that this problem is because of venesh.ir website?

Upvotes: 3

Views: 5805

Answers (2)

Fateme Ghasemi
Fateme Ghasemi

Reputation: 285

The answer of @mweiss was true, and an alternative way that I found is Setting HOST value to venesh.ir in my request header then the tcp reverse proxy works fine.

Upvotes: 1

mweiss
mweiss

Reputation: 1373

It appears that http://venesh.ir/webservice/oauth/token expects the host header to be venesh.ir. You can test this from the command line. If the host header is not venesh.ir, it will return 404:

$ curl -I -H 'Host: 1.1.1.1'  http://venesh.ir/webservice/oauth/token
HTTP/1.1 404 Not Found
Date: Mon, 24 Jun 2019 17:48:56 GMT
Server: Apache/2
Content-Type: text/html; charset=iso-8859-1

You can add the host header to your configuration if you change your mode to http:

frontend localhost
    bind *:8081
    option httplog
    mode http
    default_backend venesh

backend venesh
    mode http
    balance roundrobin
    http-request set-header Host venesh.ir
    server web01 venesh.ir:80 check

Upvotes: 3

Related Questions