简体   繁体   English

使用PHP包含的负载均衡器,是否可以仅包含服务器A中的文件

[英]Load balancer with PHP include, can I include the file from only server A

If I'm using a load balancer with 2 droplets on Digital Ocean. 如果我在Digital Ocean上使用带有2个液滴的负载平衡器。

I want to use a PHP include for an HTML file. 我想对HTML文件使用PHP包含。

is there anyway to only include the file from server A, not server B? 无论如何,仅包含服务器A中的文件,而不包含服务器B中的文件?

The use case is that these html files are generated by my customer, and will be written to a single server. 用例是这些html文件由我的客户生成,并将被写入单个服务器。

You can write an if statement: 您可以编写一条if语句:

if ($_SERVER['SERVER_NAME'] == "servera.yourdomain.com") {
    include("file.html");
} else {
    include("http://servera.yourdomain.com/path/to/file.html");
}

Note that this will only work for static files like HTML. 请注意,这仅适用于HTML之类的静态文件。 If you try to include a PHP file through the webserver, it will be executed on the remote server instead of returning the source code. 如果您尝试通过Web服务器包含一个PHP文件,它将在远程服务器上执行,而不是返回源代码。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM