Pivotal uses Haproxy as its access portal, which is, of course, allowed to be replaced with other load balancer software or hardware. However, for fear of trouble and obsessive-compulsive disorder, individuals still use Haproxy to the final production environment. In order to meet specific application requirements and reliability requirements, the Load Balancer layer has been configured, this article through four cases to share these experiences.
Assigning different haproxy to different applications
In the Pivotal Cloud Foundry Configuration Interface, Haproxy allows multiple IPs to be configured (at the same time you need to configure the same number of haproxy virtual machines on the resource size page) so that a CF has multiple portals. It can be assigned to different haproxy on the basis of load and security for different applications running on this set of CF through the human brain of the administrator. The concrete examples are as follows:
Assuming that two haproxy (10.20.30.40 and 10.20.30.41) are configured for PCF, on DNS, the *.pcf.mydomain.com subdomain is assigned to this PCF by default, pointing to 10.20.30.40. At this point, if the app App1 domain name is app1.pcf.mydomain.com, access to the app will go through 10.20.30.40 into the PCF.
At this point, if the application App1 needs to use the domain name app1.mydomain.com, and the load is high and/or the reliability requirement, you can point app1.mydomain.com to 10.20.30.41 in DNS, and then cf create-domain org1 mydomain.com Create the domain name (if the domain name is the entire CF, use it cf create-shared-domain ), then cf map-route app1 mydomain.com -n app1 add a new domain name for the application.
At this point, the application can be accessed through both app1.mydomain.com and app1.pcf.mydomain.com, but the former enters the PCF through the 10.20.30.41, which enters the PCF through 10.20.30.40.
Configure SSL certificates for different domains on the same haproxy and automatically access HTTPS
PCF can generate a self-signed domain name assigned to its own subdomain, but the actual production of the use of certificates will not be self-signed, and most will not be the domain name of the entire subdomain, but a separate domain name, or for the previous instance, add the following requirements: Another application app2 and App1 belong to the same system, Both domain app2.mydomain.com,app1.mydomain.com and app2.mydomain.com are required to have their own SSL certificates, both of which require HTTP access forbidden.
At this point, the DNS on the app2.mydomain.com point to 10.20.30.41, and then login 10.20.30.41 this haproxy os (user name is Vcap, password can be pivotal operation Manager's interface) for Haproxy configuration.
The need to automatically jump to HTTPS can be done by modifying the http-in in the/var/vcap/jobs/haproxy/config/haproxy.config.
frontend http-in mode http bind :80 option httplog option forwardfor reqadd X-Forwarded-Proto:\ http acl is_app1_mydomain_com hdr(host) -i app1.mydomain.com redirect location https://app1.mydomain.com:443 if is_app1_mydomain_co acl is_app2_mydomain_com hdr(host) -i app2.mydomain.com redirect location https://app2.mydomain.com:443 if is_app2_mydomain_com default_backend http-routers
For multiple certificate requirements, you can do so by modifying the https-in in/var/vcap/jobs/haproxy/config/haproxy.config. Upload the required certificate to this haproxy and add it in the configuration file, in the format supported by the certificate file, see/VAR/VCAP/JOBS/HAPROXY/CONFIG/CERT.PEM.
frontend https-in mode http bind :443 ssl crt /var/vcap/jobs/haproxy/config/cert.pem crt /var/vcap/jobs/haproxy/config/app1.mydomain.com.pem crt /var/vcap/jobs/haproxy/config/app2.mydomain.com.pem option httplog option forwardfor option http-server-close reqadd X-Forwarded-Proto:\ https default_backend http-routers
How to configure and use the Haporxy (on) in pivotal Cloud Foundry