Search code examples
nginxgoogle-cloud-platformbitnamigoogle-cloud-cdn

How to set up a Google VM (instance grouped), https load balanced w/CDN, so that the backend resolves the domain?


Backend: "Bitnami WordPress with NGINX and SSL Stack for Google Cloud Platform" from marketplace.

I used this guide: https://www.am22tech.com/google-cloud-cdn-wordpress/

I ended up with a somewhat working system as follows:

My Domain ->(google managed cert)-> CDN + Load Balancer -> Instance Group ->(http)-> VM with bitnami stack.

All works well and seems very fast. The biggest gap in my understanding is how the VM can be told it needs to behave as if it's the original domain.

For example, in the nginx server config, any kind of reference to $host seems to return the VM's IP address or something like that.

Also, in wordpress, in a lot of places the domain is replaced by an IP address, even though the site URL and wordpress address show up correctly. This isn't a wordpress question though, as I'm quite sure there is a more general solution I'm missing to do perhaps with NGINX or the load balancer configuration. I think PHP detects the host and passed it along to wordpress but I'm not clear how.

I found a reference somewhere in the google documentation how to manually assign a domain to a VM but not sure that's what's needed here.

Further to this, I'm totally unclear how I would set up https between the vm and the load balancer, yet only have one domain/ip address for the global forward rule. Maybe a separate question.


Solution

  • Bitnami Engineer here. If you already have the domain, certificates and the Load Balancer in place, you will need to configure WordPress to use that domain name as default domain of the application. You will need to edit the wp-config.php file and configure these lines

    define('WP_SITEURL', 'http://DOMAIN/');
    define('WP_HOME', 'http://DOMAIN/');
    

    More info: https://docs.bitnami.com/google/apps/wordpress-pro/administration/configure-domain/

    In case you also want NGINX to redirect you your domain, no matter how you access your app's information, you can add this configuration line

      return 301 https://DOMAIN$request_uri;
    

    in the /opt/bitnami/nginx/conf/bitnami/bitnami.conf file

    More info: https://docs.bitnami.com/google/apps/wordpress-pro/administration/force-https-nginx/