【问题标题】:Cannot access tomcat instance installed in EC2无法访问安装在 EC2 中的 tomcat 实例
【发布时间】:2014-03-24 20:03:46
【问题描述】:

我已经在 Ubuntu EC2 实例中安装了 tomcat 7。它已启动并正在运行,但我无法使用公共 ip (54.213.225.148:8080) 访问它。我还设置了之前帖子中指定的安全组。但是,仍然没有运气。

对此的任何帮助将不胜感激。

【问题讨论】:

  • 你能从实例本身连接到它吗(curl localhost:8080...)?
  • ec2实例是否也在运行ubuntu?你在 Ubuntu 简单防火墙上打开 8080 到 tcp 了吗? wiki.ubuntu.com/UncomplicatedFirewall
  • @UriAgassi : localhost:8080 工作正常。问题是我无法从公共 ip 访问它
  • @jeremyjjbrown 我试过 sudo ufw 允许 ssh/tcp。但仍然是同样的问题
  • 您的实例的安全组是default?

标签: tomcat amazon-web-services amazon-ec2 ubuntu-server


【解决方案1】:

确保您的 Ubuntu Uncomplicated Firewall 控制流量而不是 iptables。

sudo ufw enable

然后to configure it 允许 8080。

sudo ufw allow 8080

【讨论】:

  • 非常感谢。有效。要添加的另一件事是您必须重新启动服务器才能使更改生效。
  • 欢迎您。我假设您在 ufw enable 之后但在打开 8080 之前重新启动。
  • @jeremyjjbrown,完成后我无法 ssh 进入机器。有什么建议吗?
  • 阿里巴巴允许 22 端口吗?
  • @user3705478 我不会在 EC2 中使用 UFW,而是使用 AWS 安全组。
【解决方案2】:

您也应该将端口号添加到系统中的防火墙设置中。

sudo iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

8080 是 tomcat 端口号。

【讨论】:

  • 感谢您的回复。我已经尝试过了。但还是一样的结果。 :(
  • 试试这个 sudo service iptables stop
【解决方案3】:

在 EC2 中的 Ubuntu 14.04 上

#to save the rules you have created and to load them when the server starts.
sudo apt-get install iptables-persistent
sudo service iptables-persistent start

#the rule that explicitly accepts your current SSH connection
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
#block all incoming traffic, except for those: 22 for SSH and 80 for web traffic
sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT
#block the remaining traffic
sudo iptables -A INPUT -j DROP
#allow loopback access
sudo iptables -I INPUT 1 -i lo -j ACCEPT
#save changes
sudo /etc/init.d/iptables-persistent save

#allow port 8080
sudo iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT
sudo /etc/init.d/iptables-persistent save

更多关于 Ubuntu 上的 iptables

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-using-ip-tables-on-ubuntu-12-04 https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-using-iptables-on-ubuntu-14-04

【讨论】:

    【解决方案4】:

    仅仅通过启用 HTTP/HTTPS 是行不通的。您还需要启用 TCP 端口。

    此外,它不必只是公共 IP,即使它位于您的 VPC 中,您也可以使用私有 IP 地址访问 tomcat。

    【讨论】:

      【解决方案5】:

      在 Windows Server 2016 中

      1. 在 AWS -> 启用 EC2 的安全组:

        • 入站规则(所有流量 - 任何地方)
        • 出站规则(所有流量 - 任何地方)
      2. 在远程 EC2 上打开 -> “具有高级安全性的 Windows 防火墙”并打开

        • 入站(所有端口)
        • 出站(所有端口)

      这对我有用。

      PD:小心这个配置很不安全。

      【讨论】:

        猜你喜欢
        • 2015-11-25
        • 2017-11-07
        • 2016-11-14
        • 1970-01-01
        • 2016-01-25
        • 2017-05-03
        • 2023-04-06
        • 1970-01-01
        • 2018-12-12
        相关资源
        最近更新 更多