dtgu21994537 2019-07-08 23:42
浏览 33
已采纳

使用PHP包含负载均衡器,我可以只包含来自服务器A的文件

If I'm using a load balancer with 2 droplets on Digital Ocean.

I want to use a PHP include for an HTML file.

is there anyway to only include the file from server A, not server B?

The use case is that these html files are generated by my customer, and will be written to a single server.

  • 写回答

1条回答 默认 最新

  • dongzhi1904 2019-07-09 00:05
    关注

    You can write an if statement:

    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. 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?