0

我有 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我会收到正确的重定向到谷歌。但是当我使用公共弹性搜索请求时,它一直处于挂起状态。当我tcptruck在服务器上运行et1并在我的计算机上向弹性 IP 发出请求时,在服务器中我看到该请求和请求状态仍然显示SYN_SENT。我应该怎么做才能使 nginx 正常工作?

编辑: 172.31.13.104是私有IPet1

4

2 回答 2

1

I had the same problem and this is how I solved it. You need two ENIs with their own ips, you need to configure them to their respective domain, then you create a config file for each of the two connections.

Below is what I had to do on my rhel server to get it to work.

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

-- changed DEVICE="eth0" to DEVICE="eth1" and saved the file

  $ 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

-- please replace 172.31.48.1 with your interface's Gateway (you will get this from 'route -n' output) -- replace 172.ip1 with eth0's private IP address and 172.ip2 with eth1's private IP address (you will get these from 'ifconfig' output)

$ sudo chmod +x /etc/rc.local

After that, please reboot or Stop/Start the instance and once the instance boots up, you will be able to login using either of the EIPs. Once you are logged in, you may verify whether both the interfaces can communicate over the internet by running the following commands:

$ 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)

You should get ping response from both the pings.

Once you're through this, you'll need to configure IP based virtual hosts in apache [5]. This will let you fetch different contents from different directories for different domain/sub-domain.

Then, you will need to create a resource record sets [6] to route traffic for a subdomain called 'poc.domain.com' to an IP address (eth1's EIP in your case).

Finally, you will need to associate/change security groups [7] of each ENIs (eth0 and eth1) as per your requirement.

于 2017-04-23T18:43:59.377 回答
0

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

于 2017-04-23T16:19:54.307 回答