简体   繁体   English

如何设置Google VM(实例分组),https负载均衡(带有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. 后端:来自市场的“带有NGINX和SSL堆栈的Bitnami WordPress,适用于Google Cloud Platform”。

I used this guide: https://www.am22tech.com/google-cloud-cdn-wordpress/ 我使用了此指南: 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. 我的域->(由Google管理的证书)-> CDN +负载均衡器->实例组->(http)->具有bitnami堆栈的VM。

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. 据我了解,最大的差距是如何告知VM需要表现得好像是原始域一样。

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. 例如,在Nginx服务器配置中,对$ host的任何引用似乎都会返回VM的IP地址或类似的东西。

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. 同样,在wordpress中,即使站点URL和wordpress地址正确显示,在很多地方该域也被IP地址代替。 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. 不过,这不是WordPress的问题,因为我敢肯定,我缺少使用NGINX或负载均衡器配置的更通用的解决方案。 I think PHP detects the host and passed it along to wordpress but I'm not clear how. 我认为PHP可以检测到主机并将其传递给wordpress,但是我不清楚如何。

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. 我在google文档的某处找到了有关如何手动将域分配给VM的参考,但不确定此处是否需要该参考。

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. 除此之外,我还不清楚如何在虚拟机和负载均衡器之间设置https,但是对于全局转发规则只有一个域/ ip地址。 Maybe a separate question. 也许是一个单独的问题。

Bitnami Engineer here. Bitnami工程师在这里。 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. 如果您已经拥有域,证书和负载均衡器,则需要配置WordPress以使用该域名作为应用程序的默认域。 You will need to edit the wp-config.php file and configure these lines 您将需要编辑wp-config.php文件并配置这些行

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

More info: https://docs.bitnami.com/google/apps/wordpress-pro/administration/configure-domain/ 更多信息: 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 如果您还希望NGINX重定向您的域,无论您如何访问应用程序信息,都可以添加此配置行

  return 301 https://DOMAIN$request_uri;

in the /opt/bitnami/nginx/conf/bitnami/bitnami.conf file 在/opt/bitnami/nginx/conf/bitnami/bitnami.conf文件中

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

I had better luck having the load balancer talk to my VM with https. 我比较幸运的是让负载均衡器通过https与我的VM通讯。 Once I got that working, I didn't have to make any changes to wp-config.php. 一旦完成该工作,就无需对wp-config.php进行任何更改。 In this case I didn't bother with varnish because I think it only supports http. 在这种情况下,我不必理会清漆,因为我认为它仅支持http。 I'm hoping google's CDN will be sufficient regarding caching, and I may try a helper plugin in wordpress. 我希望Google的CDN在缓存方面足够了,我可以在wordpress中尝试一个辅助插件。

To redirect http to https, I followed the bitnami instructions to set up to front ends to the load balancer pointing to the same static ip address, then in my nginx server blocks, I added a redirect line in the https block (not the http block), since the google load balancer communicates with my backend via https. 要将http重定向到https,我按照bitnami指令将前端设置为指向相同静态IP地址的负载均衡器,然后在我的nginx服务器块中,在https块(不是http块)中添加了重定向行),因为Google负载均衡器通过https与我的后端进行通信。 Google sets the http_x_fowward_proto to http so I check that and redirect if necessary. Google将http_x_fowward_proto设置为http,因此我进行了检查,并在必要时重定向。

if ($http_x_forwarded_proto = "http") { return 301 https://$host$request_uri; 如果($ http_x_forwarded_proto =“ http”){返回301 https:// $ host $ request_uri; } }

The bitnami stack is amazing, everything seems extremely fast! bitnami堆栈很棒,一切似乎都非常快!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Elastic Load Balancer 在 Amazon EC2 上设置 HTTPS - How to set up HTTPS on Amazon EC2 with Elastic Load Balancer 如何为 Rasa 聊天机器人设置 HTTPS? - How to set up HTTPS for Rasa chatbot? 使用$ http_x_forwarded_proto强制使用NGINX上的www和https重定向作为Google云负载均衡器的后端 - Forcing www and https redirect on NGINX as backend of Google cloud Load Balancer using $http_x_forwarded_proto 如何通过HTTPS测试特定的负载均衡器实例? - How do I test an specific load balancer instance over HTTPS? Map 谷歌云虚拟机 docker 端口到 HTTPS - Map Google Cloud VM docker port to HTTPS 如何将请求转发到 https 后端 - how to forward request to https backend 如何将nginx与Kubernetes(GKE)和Google HTTPS负载均衡器配合使用 - How to use nginx with Kubernetes (GKE) and Google HTTPS load balancer 如何使用Nginx设置从http到https的重定向? - How to set up redirect from http to https with nginx? 如何设置Beanstalk + Nginx将HTTP重定向到https? - How to set up Beanstalk + Nginx to redirect http to https? 负载平衡-如何正确设置? - Load Balancing - How to set it up correctly?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM