简体   繁体   English

亚马逊AWS EC2 GoLang

[英]Amazon AWS EC2 GoLang

I have a small Go web server which I have deployed on Amazon Web Services but I am having trouble getting to work. 我有一个小的Go Web服务器,我已部署在Amazon Web Services上,但我无法上班。

My EC2 instance has both public & private IP addresses assigned, but I am unable to start the Go server. 我的EC2实例分配了公共和私有IP地址,但我无法启动Go服务器。

If I serve it on localhost it works, but obviously I can't connect to it, so I am trying to assign it the public ip, but it crashes without throwing any errors. 如果我在localhost上提供它它可以工作,但显然我无法连接到它,所以我试图将它分配给公共IP,但它崩溃而不会丢失任何错误。

http.ListenAndServe("public_ip", nil)

Any ideas how to proceed from here? 有什么想法从这里开始?

I'm not sure what does it mean that your server crashes without throwing any errors . 我不确定你的服务器在没有丢失任何错误的情况下崩溃是什么意思。 Make sure you're logging the error: 确保您记录错误:

log.Println(http.ListenAndServe(addr, nil))

This should give you some idea why it doesn't work. 这应该会让你知道为什么它不起作用。 Anything there? 还有什么吗?

For example, when running on port < 1024 without root privileges, I can see: 例如,当在没有root权限的端口<1024上运行时,我可以看到:

2014/11/25 19:14:51 listen tcp :80: bind: permission denied

Now, if you run the server on address :8080 , you should be listening on all the interfaces. 现在,如果您在地址:8080上运行服务器,您应该监听所有接口。 You can test the server from the local host. 您可以从本地主机测试服务器。 If it works, make sure your machine is reachable from the Internet on this port by modifying security group for your instance. 如果可行,请通过修改实例的安全组 ,确保可以从此端口上的Internet访问您的计算机。

If it still doesn't work, please let us know what does and a little bit more about the crash . 如果它仍然无法正常工作,请告诉我们有关崩溃的内容和更多内容。

A couple things to check: 要检查几件事:

  • Your public IP does not exist at the local machine (it is NATed), listen for the private address or 0.0.0.0 for all. 您的公共IP在本地计算机上不存在(它是NAT),监听私有地址或全部0.0.0.0。
  • If it is connecting from localhost but not remotely, make sure: 如果它是从localhost连接但不是远程连接,请确保:

    • That the instance's security group has an inbound rule allowing the port and source. 实例的安全组具有允许端口和源的入站规则。
    • If it is on a VPC, that the VPC is attached to an Internet Gateway and there is a route to it. 如果它在VPC上,则VPC连接到Internet网关并且存在到其的路由。

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

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