php - 设置 haProxy 以在 Appfog 上切换多个应用程序的内容

标签 php node.js haproxy appfog

我目前在 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/

相关文章:

node.js - 为什么服务总线上的消息会随机丢失?我做错了什么?

ssl - 如何让 docker cloud(以前称为 tutum)和 haproxy 使用 SSL?

python - 区分nginx、haproxy、varnish和uWSGI/Gunicorn

php - 从其 "correct"源抛出错误

php - 接口(interface)的现实世界实现

javascript - Linux 下 node.js C++ 插件中的 undefined symbol ,为什么?

Node.js ssh2-sftp-客户端错误 : fastPut: No response from server Local

ssl - 使用 Haproxy 代理到安全站点

javascript - 当使用多种编码时如何分离 json 解析的数据?

php - 如何从 php 字符串中删除新行和返回?