【问题标题】:Nginx don't handle request if I make request by AWS elastic IP如果我通过 AWS 弹性 IP 发出请求,Nginx 不处理请求
【发布时间】:2017-04-24 02:43:59
【问题描述】:

我有 ec2 实例,它有 2 个接口,et0 和 et1。我为该接口分配了 2 个弹性 IP。 et0 运行良好,对分配给该 IP 的 IP 的请求由具有 listen 80 default_server; nginx 配置的服务器处理。在/etc/nginx/sites-available/default 中,我为第二个接口 et1 进行了配置:

server {
    listen 172.31.13.104:80;
    #listen [::]:80 default_server;
    server_name example2.com;
    return 301 http://google.com;
}

如果我从第二个 aws 实例向 172.31.13.104 发出请求,我会收到正确的重定向到谷歌。但是当我使用公共弹性搜索时,请求一直处于挂起状态。当我在et1 上的服务器上运行tcptruck 并在我的计算机上向弹性IP 发出请求时,在服务器中我看到该请求和请求状态仍然显示SYN_SENT。我应该怎么做才能让 nginx 正常工作?

编辑: 172.31.13.104et1 的私有 IP

【问题讨论】:

  • 端口80是否在分配给实例的安全组以及在实例上运行的任何防火墙软件(例如iptables)中都打开?

标签: amazon-web-services nginx amazon-ec2 elastic-ip


【解决方案1】:

我遇到了同样的问题,这就是我解决它的方法。您需要两个具有自己 ips 的 ENI,您需要将它们配置到各自的域,然后为两个连接中的每一个创建一个配置文件。

以下是我必须在我的 rhel 服务器上执行的操作。

$ cd /etc/sysconfig/network-scripts
 $ sudo cp ifcfg-eth0 ifcfg-eth1
$ sudo vi ifcfg-eth1

-- 将 DEVICE="eth0" 更改为 DEVICE="eth1" 并保存文件

  $ sudo vi /etc/rc.local
 -- added the following lines and saved the file ip route add default via 172.31.48.1 dev eth0 table 20 ip rule add from 172.ip1 table 20 ip
 route add default via 172.31.48.1 dev eth1 table 21 ip rule add from
 172.ip2 table 21

-- 请将 172.31.48.1 替换为您接口的网关(您将从 'route -n' 输出中获得) -- 将 172.ip1 替换为 eth0 的私有 IP 地址,将 172.ip2 替换为 eth1 的私有 IP 地址(您将从 'ifconfig' 输出中获得这些)

$ sudo chmod +x /etc/rc.local

之后,请重启或停止/启动实例,一旦实例启动,您将能够使用任一 EIP 登录。登录后,您可以通过运行以下命令来验证两个接口是否可以通过 Internet 进行通信:

$ ping -I eth0 google.com (this will ping google.com from interface eth0)
$ ping -I eth1 google.com (this will ping google.com from interface eth1)

您应该从两个 ping 中获得 ping 响应。

完成此操作后,您需要在 apache [5] 中配置基于 IP 的虚拟主机。这将让您从不同的目录中为不同的域/子域获取不同的内容。

然后,您将需要创建一个资源记录集 [6] 以将名为“poc.domain.com”的子域的流量路由到 IP 地址(在您的情况下为 eth1 的 EIP)。

最后,您需要根据您的要求关联/更改每个 ENI(eth0 和 eth1)的安全组 [7]。

【讨论】:

    【解决方案2】:

    问题由我自己解决。我的 IP 路由规则不正确,这里是如何配置 ip 表 https://www.lisenet.com/2014/create-and-attach-a-second-elastic-network-interface-with-eip-to-ec2-vpc-instance/ 的教程

    【讨论】:

      猜你喜欢
      • 2012-01-21
      • 1970-01-01
      • 2013-11-22
      • 2015-01-22
      • 2018-08-25
      • 2011-03-27
      • 1970-01-01
      • 1970-01-01
      • 2018-01-31
      相关资源
      最近更新 更多