Deprecated: Return type of WP_Theme::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/class-wp-theme.php on line 554

Deprecated: Return type of WP_Theme::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/class-wp-theme.php on line 595

Deprecated: Return type of WP_Theme::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/class-wp-theme.php on line 535

Deprecated: Return type of WP_Theme::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/class-wp-theme.php on line 544

Deprecated: Return type of WP_REST_Request::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/rest-api/class-wp-rest-request.php on line 960

Deprecated: Return type of WP_REST_Request::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/rest-api/class-wp-rest-request.php on line 980

Deprecated: Return type of WP_REST_Request::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/rest-api/class-wp-rest-request.php on line 992

Deprecated: Return type of WP_REST_Request::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/rest-api/class-wp-rest-request.php on line 1003

Deprecated: Return type of WP_Block_List::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/class-wp-block-list.php on line 151

Deprecated: Return type of WP_Block_List::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/class-wp-block-list.php on line 175

Deprecated: Return type of WP_Block_List::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/class-wp-block-list.php on line 164

Deprecated: Return type of WP_Block_List::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/class-wp-block-list.php on line 186

Deprecated: Return type of WP_Block_List::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/class-wp-block-list.php on line 138

Deprecated: Return type of WP_Block_List::offsetExists($index) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/class-wp-block-list.php on line 75

Deprecated: Return type of WP_Block_List::offsetGet($index) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/class-wp-block-list.php on line 89

Deprecated: Return type of WP_Block_List::offsetSet($index, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/class-wp-block-list.php on line 110

Deprecated: Return type of WP_Block_List::offsetUnset($index) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/class-wp-block-list.php on line 127

Deprecated: Return type of WP_Block_List::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/johnmark_507/public/wp-includes/class-wp-block-list.php on line 199

Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in /www/johnmark_507/public/wp-content/plugins/wordpress-seo/src/conditionals/third-party/elementor-edit-conditional.php on line 22

Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in /www/johnmark_507/public/wp-content/plugins/wordpress-seo/src/conditionals/third-party/elementor-edit-conditional.php on line 28

Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-includes/class-wp.php on line 173

Deprecated: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-includes/wp-db.php on line 3030
Host Multiple Web Sites with Nginx and HAProxy Using LXD from Google Cloud Platform machines - John Mark C
Deprecated: parse_str(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-includes/formatting.php on line 4975

Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/plugins/wordpress-seo/src/generators/schema-generator.php on line 176

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

John Mark Causing

System Administrator | Hosting Support Engineer

johnmarkcausing@gmail.com

Bacolod City, Philippines

+639393497018

John Mark Causing

System Administrator | Hosting Support Engineer

johnmarkcausing@gmail.com

Bacolod City, Philippines

+639393497018

We are following this original tutorial by Simos so we are just tweaking this for Google Cloud Platform to make sure HAProxy will work properly.

We assume that LXD has been already setup from that guide and we are now on step 3 where containers are already created.

The difference on this tutorial if you are using Google Cloud containers is that there’s no need to specify the IP address. GCP is using NAT on all Virtual Machines so the GCP container/main host does not actually own the IP address and we are just removing this.

-d your_server_ip/32

From the original tutorial command for IP tables:

sudo iptables -t nat -I PREROUTING -i eth0 -p TCP -d your_server_ip/32 --dport 80 -j DNAT --to-destination your_haproxy_ip:80

Command that we should be using for GCP (Google Cloud Platform) <– We we will this later after we flushed the IP tables.

sudo iptables -t nat -I PREROUTING -i ens4 -p TCP --dport 80 -j DNAT --to-destination 10.22.74.193:80

10.22.74.193 is the HAProxy IP from the LXC list (screenshot above).

Clearing the IP Tables using this bash script:

#!/bin/sh
echo "Flushing iptables rules..."
sleep 1
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

ens4 is the Network Infterace Card name of the GCP machine. You can get that using “ifconfig” command

Execute the IP Tables command

(10.22.74.193 is the IP of our HAProxy container)

sudo iptables -t nat -I PREROUTING -i ens4 -p TCP --dport 80 -j DNAT --to-destination 10.22.74.193:80

Your IP Address from GCP

Save the IP tables.

sudo /sbin/iptables-save

My DNS settings for that subdomain

Testing HAProxy

34.96.177.142 is the IP of your GCP machine

curl --verbose --header 'Host: lxd1.johnmark.me' https://34.96.177.142

Adding another site

edit the haproxy.cfg file then add the other domain

Test the haproxy config file and reload it.

Adding the domain to my DNS list

And see the beauty of HAProxy

I hope you enjoyed this article! 🙂


Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71

Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/class-et-builder-element.php on line 19534

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/johnmark_507/public/wp-content/themes/Divi/includes/builder/module/helpers/HoverOptions.php on line 71