通过 haproxy 调用请求时获取 404(直接工作正常)
Getting 404 when call request by haproxy (directly works fine)
我直接用 url 调用网络服务
curl http://venesh.ir/webservice/oauth/token
我收到错误 403,
但是当我从某个服务器通过反向代理调用它时,我得到了 404,haproxy 是否可能更改我的地址?
haproxy 配置:
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
当我调用 mySerevrIp:8081/webservice/oauth/token
时,我希望得到我直接调用的结果
curl http://venesh.ir/webservice/oauth/token
即403,
但是当我调用 curl mySerevrIp:8081/webservice/oauth/token
时出现错误 404,
我的 haproxy 或我的配置有问题,还是这个问题可能是因为 venesh.ir 网站?
看来 http://venesh.ir/webservice/oauth/token
期望主机 header 是 venesh.ir
。您可以从命令行对此进行测试。如果主机 header 不是 venesh.ir
,它将 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
如果您将模式更改为 http:
,则可以将主机 header 添加到您的配置中
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
@mweiss 的回答是正确的,我发现的另一种方法是在我的请求 header 中将 HOST
值设置为 venesh.ir
然后 tcp 反向代理工作正常。
我直接用 url 调用网络服务
curl http://venesh.ir/webservice/oauth/token
我收到错误 403,
但是当我从某个服务器通过反向代理调用它时,我得到了 404,haproxy 是否可能更改我的地址?
haproxy 配置:
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
当我调用 mySerevrIp:8081/webservice/oauth/token
时,我希望得到我直接调用的结果
curl http://venesh.ir/webservice/oauth/token
即403,
但是当我调用 curl mySerevrIp:8081/webservice/oauth/token
时出现错误 404,
我的 haproxy 或我的配置有问题,还是这个问题可能是因为 venesh.ir 网站?
看来 http://venesh.ir/webservice/oauth/token
期望主机 header 是 venesh.ir
。您可以从命令行对此进行测试。如果主机 header 不是 venesh.ir
,它将 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
如果您将模式更改为 http:
,则可以将主机 header 添加到您的配置中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
@mweiss 的回答是正确的,我发现的另一种方法是在我的请求 header 中将 HOST
值设置为 venesh.ir
然后 tcp 反向代理工作正常。