通过haproxy将请求转发给cpanel服务器

时间:2017-05-09 18:12:58

标签: redirect load-balancing cpanel haproxy

我部署了负载平衡的基础设施。我使用haproxy作为负载均衡器,使用cpanel作为后端Web服务器。我在cpanel上创建了一个测试主机,当我在/ etc / host中使用cpanel服务器ip地址配置网站时,我可以在浏览器中看到该站点。但是当我将ip更改为loadbalancer时,它会将请求转发到/ usr / local / apache / htdocs /,然后我得到默认的cpanel服务器页面。我应该在haproxy中使用哪些配置来正确地重定向请求? 任何帮助表示赞赏。

# Global settings
#---------------------------------------------------------------------
global
    log         127.0.0.1 local2     #Log configuration

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy             #Haproxy running under user and group "haproxy"
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

#---------------------------------------------------------------------
#HAProxy Monitoring Config
#---------------------------------------------------------------------
listen haproxy2-monitoring *:8080                #Haproxy Monitoring run on port 8080
    mode http
 option forwardfor
    option httpclose
    stats enable
    stats show-legends
    stats refresh 5s
    stats uri /stats                             #URL for HAProxy monitoring
    stats realm Haproxy\ Statistics
    stats auth lb2:F6khdTrt9g            #User and Password for login to the monitoring dashboard
    stats admin if TRUE
    default_backend app-main                    #This is optionally for monitoring backend

#---------------------------------------------------------------------
# FrontEnd Configuration
#---------------------------------------------------------------------
frontend main
    bind *:80
    default_backend app-main

#---------------------------------------------------------------------
# BackEnd roundrobin as balance algorithm
#---------------------------------------------------------------------
backend app-main


    balance roundrobin                                     #Balance algorithm
    application is up and healty - 200 status code

    server cpanel1 192.168.1.110:80 check
    server cpanel2 192.168.1.111:80 check

Cpanel apache config:
Listen 0.0.0.0:80

# BEGIN: HTTP vhosts list

<VirtualHost 88.99.219.13:80>
  ServerName wiki.serversetup.ir
  ServerAlias mail.wiki.serversetup.ir www.wiki.serversetup.ir
  DocumentRoot /home/wiki/public_html
  ServerAdmin webmaster@wiki.serversetup.ir
  UseCanonicalName Off
  CustomLog /etc/apache2/logs/domlogs/wiki.serversetup.ir combined
  <IfModule log_config_module>
    <IfModule logio_module>
      CustomLog /etc/apache2/logs/domlogs/wiki.serversetup.ir-bytes_log "%{%s}t %I .\n%{%s}t %O ."
    </IfModule>
  </IfModule>
  ## User wiki # Needed for Cpanel::ApacheConf
  <IfModule userdir_module>
    <IfModule !mpm_itk.c>
      <IfModule !ruid2_module>
        UserDir disabled
        UserDir enabled wiki
      </IfModule>
    </IfModule>
  </IfModule>

  # Enable backwards compatible Server Side Include expression parser for Apache versions >= 2.4.
  # To selectively use the newer Apache 2.4 expression parser, disable SSILegacyExprParser in
  # the user's .htaccess file.  For more information, please read:
  #    http://httpd.apache.org/docs/2.4/mod/mod_include.html#ssilegacyexprparser
  <IfModule include_module>
    <Directory "/home/wiki/public_html">
      SSILegacyExprParser On
    </Directory>
  </IfModule>



  <IfModule suphp_module>
    suPHP_UserGroup wiki wiki
  </IfModule>
  <IfModule suexec_module>
    <IfModule !mod_ruid2.c>
      SuexecUserGroup wiki wiki
 </IfModule>
  </IfModule>
  <IfModule ruid2_module>
    RMode config
    RUidGid wiki wiki
  </IfModule>
  <IfModule mpm_itk.c>
    # For more information on MPM ITK, please read:
    #   http://mpm-itk.sesse.net/
    AssignUserID wiki wiki
  </IfModule>

  <IfModule alias_module>
    ScriptAlias /cgi-bin/ /home/wiki/public_html/cgi-bin/
  </IfModule>


  # To customize this VirtualHost use an include file at the following location
  # Include "/etc/apache2/conf.d/userdata/std/2_4/wiki/wiki.serversetup.ir/*.conf"
</VirtualHost>
# END: HTTP vhosts list

0 个答案:

没有答案