【问题标题】:Using Apache2 behind HAProxy is not working properly在 HAProxy 后面使用 Apache2 无法正常工作
【发布时间】:2015-05-07 18:16:56
【问题描述】:

我在 haproxy 1.5 后面的 ubuntu 12.04 上使用 apache 2.2。我的 haproxy 正在侦听端口 80,而 apache 正在侦听端口 8000。我想做的是,我想将 haproxy 上带有路径“/test”的任何请求转发到我的 apache。

我有一个托管在“/var/www/test”中的 wordpress 应用程序。

我面临的问题是,如果我尝试使用 http://www.example.com/test 访问测试应用程序,apache 会将其重定向到 http://www.example.com:8000/test/ 。知道为什么会这样吗?我错过了什么?

这里是配置:

ports.conf:

NameVirtualHost *:8000
Listen 8000

<IfModule mod_ssl.c>
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

网站可用/默认:

<VirtualHost *:8000>
        ServerName www.example.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory "/var/www">
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

 </VirtualHost>

haproxy.cfg:

frontend http-in
      bind *:80
      acl is_test path_beg /test
      use_backend test_backend if is_test

backend test_backend
      balance roundrobin
      option forwardfor
      server Local localhost:8000 check

当我将它登录到 index.php 时,我发现 $_SERVER['HTTP_X_FORWARDED_HOST'] 是空的。知道为什么会这样。

【问题讨论】:

    标签: wordpress apache load-balancing haproxy


    【解决方案1】:

    问题在于 Wordpress。检查您的“站点地址 (URL)”设置。 Wordpress 正在将浏览器重定向到它认为自己被托管的位置。将“站点地址 (URL)”设置更改为 http://www.example.com/test 应该会阻止此操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-29
      • 2021-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-27
      相关资源
      最近更新 更多