亚马逊 AWS EC2 GoLang

huangapple go评论97阅读模式
英文:

Amazon AWS EC2 GoLang

问题

我有一个小的Go Web服务器,我已经部署在亚马逊云服务上,但是我在让它正常工作方面遇到了问题。

我的EC2实例同时分配了公有IP和私有IP地址,但是我无法启动Go服务器。

如果我在本地主机上运行它,它可以工作,但是显然我无法连接到它,所以我尝试将其分配给公有IP,但是它在没有抛出任何错误的情况下崩溃了。

http.ListenAndServe("public_ip", nil)

有什么想法如何继续处理这个问题吗?

英文:

I have a small Go web server which I have deployed on Amazon Web Services but I am having trouble getting to work.

My EC2 instance has both public & private IP addresses assigned, but I am unable to start the Go server.

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.

http.ListenAndServe("public_ip", nil)

Any ideas how to proceed from here?

答案1

得分: 6

我不确定"服务器在没有抛出任何错误的情况下崩溃"是什么意思。请确保你正在记录错误信息:

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

这应该能给你一些关于为什么不起作用的想法。有什么错误信息吗?

例如,当在没有 root 权限的情况下运行在端口号小于 1024 时,我可以看到:

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

现在,如果你在地址 :8080 上运行服务器,你应该监听所有接口。你可以从本地主机测试服务器。如果它可以工作,请确保你的机器可以通过修改实例的 安全组 在该端口上从互联网访问。

如果还是不起作用,请告诉我们发生了什么以及有关"崩溃"的更多信息。

英文:

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:

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

If it still doesn't work, please let us know what does and a little bit more about the crash.

答案2

得分: 3

有几件事情需要检查:

  • 您的公共IP地址在本地机器上不存在(它经过了NAT),请监听私有地址或使用0.0.0.0监听所有地址。

  • 如果它是从本地主机连接而不是远程连接,请确保:

  • 实例的安全组具有允许该端口和来源的入站规则。

  • 如果它在VPC上,请确保VPC已连接到Internet Gateway,并且存在到该网关的路由。

英文:

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.

  • If it is connecting from localhost but not remotely, make sure:

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

huangapple
  • 本文由 发表于 2014年11月26日 02:02:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/27133612.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定