我目前在 AppFog 有两个应用程序,它们是。
http://sru-forums-prod.aws.af.cm/和 http://sru-home-prod.aws.af.cm/
我的计算机上本地运行 haProxy,这是我当前的配置文件。
全局 调试
defaults
mode http
timeout connect 500ms
timeout client 50000ms
timeout server 50000ms
backend legacy
server forums sru-forums-prod.aws.af.cm:80
frontend app *:8232
default_backend legacy
最终目标是 localhost:8232 将流量转发到 sru-home-prod,而 localhost:8232/forums/* 将流量转发到 sru-forums-prod。但是我什至无法启动并运行一个简单的代理。
当我从此配置文件运行 HAProxy 时,我收到 AppFog 404 Not Found at localhost:8232。
我错过了什么,这可能吗?
编辑:
新配置有效,但现在我在响应中返回了端口 60032。
global
debug
defaults
mode http
timeout connect 500ms
timeout client 50000ms
timeout server 50000ms
backend legacy
option forwardfor
option httpclose
reqirep ^Host: Host:\ sru-forums-prod.aws.af.cm
server forums sru-forums-prod.aws.af.cm:80
frontend app *:8000
default_backend legacy
最佳答案
您收到 AppFog 404 Not Found 的原因是因为 AppFog 上托管的应用程序是按域名路由的。为了让 AppFog 知道哪个应用程序为您提供服务,HTTP 请求中需要包含域名。当您转到 localhost:8232/forums/时,它会发送 localhost 作为域名,而 AppFog 没有作为注册应用程序名称。
有一个好方法可以解决这个问题
1) 将您的应用程序映射到第二个域名,例如:
af map <appname> sru-forums-prod-proxy.aws.af.cm
2) 编辑/etc/hosts 文件并添加以下行:
127.0.0.1 sru-forums-prod-proxy.aws.af.cm
3) 转到http://sru-forums-prod-proxy.aws.af.cm:8232/forums/它将映射到本地计算机,但会成功地通过您的 haproxy,最终将正确的主机名映射到 AppFog 上托管的应用程序。
这是一个有效的 haproxy.conf 文件,它演示了迄今为止如何使用类似的方法为我们工作。
defaults
mode http
timeout connect 500ms
timeout client 50000ms
timeout server 50000ms
backend appfog
option httpchk GET /readme.html HTTP/1.1\r\nHost:\ aroundtheworld.appfog.com
option forwardfor
option httpclose
reqirep ^Host: Host:\ aroundtheworld.appfog.com
server pingdom-aws afpingdom.aws.af.cm:80 check
server pingdom-rs afpingdom-rs.rs.af.cm:80 check
server pingdom-hp afpingdom-hp.hp.af.cm:80 check
server pingdom-eu afpingdom-eu.eu01.aws.af.cm:80 check
server pingdom-ap afpingdom-ap.ap01.aws.af.cm:80 check
frontend app *:8000
default_backend appfog
listen stats 0.0.0.0:8080
mode http
stats enable
stats uri /haproxy
关于php - 设置 haProxy 以在 Appfog 上切换多个应用程序的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12539370/