简体   繁体   English

PHP-Amazon Elastic Beanstalk-获取私有IP地址

[英]PHP - Amazon Elastic Beanstalk - Get private IP address

I am hosting a web app in Amazon Elastic Beanstalk (EB). 我在Amazon Elastic Beanstalk(EB)中托管一个Web应用程序。 The web app is written in php. 该网络应用程序是用php编写的。 EB also uses Elastic Load Balancer (ELB). EB还使用弹性负载平衡器(ELB)。 The web app implements a websocket with the client. 该Web应用程序与客户端实现一个websocket。 Here is what I have done so far: 到目前为止,这是我所做的:

  1. I know I have to listen to the private ip, not 127.0.0.1 of the instance for this to work 我知道我必须监听私有IP,而不是实例的127.0.0.1,才能正常工作
  2. implemented a listener in load balancer to connect to the instance port 在负载均衡器中实现了侦听器以连接到实例端口
  3. opened inbound and outbound traffic for the port in security groups. 在安全组中打开了端口的入站和出站流量。

If the EB deployment goes for horizontal scaling (increase the number of instances), will the private ips of the scaled instances remain same ( please explain )? 如果EB部署用于水平扩展(增加实例数),则扩展后实例的私有IP是否保持不变( 请说明 )? If not, and I believe so, how do I get the private ip address of the current instance that is serving the client? 如果没有,并且我相信,我如何获取正在为客户端提供服务的当前实例的私有IP地址?

So far its working perfectly without any problem, but there's only one instance running. 到目前为止,它可以完美运行,没有任何问题,但是只有一个实例正在运行。 I tried listing the clients and I can get the private ips with the list but I don't know how to identify the instance that is currently serving the file. 我尝试列出客户端,并且可以使用列表获取私有ip,但是我不知道如何识别当前为文件提供服务的实例。

Please help me. 请帮我。

This will do the trick: 这将达到目的:

<?php $ip = shell_exec('hostname -i'); ?>

important: this works only for the linux environment. 重要:这仅适用于linux环境。 For windows, hostname -i is not valid. 对于Windows, hostname -i无效。 You can refer to https://superuser.com/questions/382265/ for further ideas. 您可以参考https://superuser.com/questions/382265/了解更多信息。

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

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