简体   繁体   English

如何从EC2实例重定向到我的IP

[英]How to redirect to my ip from ec2 instance

I am new to AWS. 我是AWS的新手。

I have created an instance in AWS and it has some url (ec2-xx-xx-xxx-xxx.ap-south-1.compute.amazonaws.com) and I installed jdk, tomcat7 in this instance to run my java application. 我在AWS中创建了一个实例,它具有一些URL(ec2-xx-xx-xxx-xxx.ap-south-1.compute.amazonaws.com),并且在此实例中安装了jdk tomcat7来运行我的Java应用程序。

This url was already shared with users to access. 此URL已与用户共享以访问。 And I have a static IP which has 8GB RAM. 我有一个具有8GB RAM的静态IP。

Now I want to redirect to my IP address while users hit the AWS url. 现在,我想在用户点击AWS URL时重定向到我的IP地址。 Is this possible? 这可能吗?

Can anyone assist me, I cant found solution for this in my searches. 谁能帮助我,我在搜索中找不到解决方案。

If you are asking how to redirect your ec2-xx-xx-xxx-xxx.ap-south-1.compute.amazonaws.com address to a different IP address, then this is not possible . 如果您要询问如何将ec2-xx-xx-xxx-xxx.ap-south-1.compute.amazonaws.com地址重定向到其他IP地址,那么这是不可能的 That DNS name always resolves to the IP address given in the name. 该DNS名称始终解析为名称中给定的IP地址。

Correct practice is to create an Elastic IP address , assign it to an Amazon EC2 instance (so it always has the same IP address) and then create a DNS A record to point to that IP address. 正确的做法是创建一个弹性IP地址 ,将其分配给Amazon EC2实例(因此它始终具有相同的IP地址),然后创建一个指向该IP地址的DNS A记录。 You can create the DNS record in whatever system controls your domain name (eg Amazon Route 53, GoDaddy). 您可以在控制您域名的任何系统中创建DNS记录(例如Amazon Route 53,GoDaddy)。

Also, please note that your existing IP address might change if you stop and start your Amazon EC2 instance. 另外,请注意,如果您停止并启动Amazon EC2实例,则您现有的IP地址可能会更改。 This does not happen with an Elastic IP address. 弹性IP地址不会发生这种情况。

How many IP address or elastic network interfaces (ENIs) are attached to your instance? 您的实例连接了多少个IP地址或弹性网络接口(ENI)? As @John Rotenstein has mentioned, you cannot redirect 正如@John Rotenstein提到的那样,您无法重定向

ec2-xx-xx-xxx-xxx.ap-south-1.compute.amazonaws.com ec2-xx-xx-xxx-xxx.ap-south-1.compute.amazonaws.com

to your IP address (even it is EIP) since AWS does this for you by resolving the name to your IP address. 到您的IP地址(甚至是EIP),因为AWS通过将名称解析为您的IP地址来为您完成此操作。 From AWS docs, 从AWS文档中,

A public (external) DNS hostname takes the form ec2-public-ipv4-address.compute-1.amazonaws.com for the us-east-1 region, and ec2-public-ipv4-address.region.amazonaws.com for other regions. 公用(外部)DNS主机名的格式用于ec2-public-ipv4-address.compute-1.amazonaws.com(用于us-east-1区域),以及ec2-public-ipv4-address.region.amazonaws.com(用于其他域)地区。 We resolve a public DNS hostname to the public IPv4 address of the instance outside the network of the instance, and to the private IPv4 address of the instance from within the network of the instance. 我们将公共DNS主机名解析为实例网络外部实例的公共IPv4地址,并解析为实例网络内部的实例私有IPv4地址。

Since the domain amazonaws.com is not in your control, you have to update your DNS record of your website (or if you don't have any, you may need to buy the domain name) so that your website points to your EC2 instance's IP. 由于域名amazonaws.com不在您的控制范围内,因此您必须更新网站的DNS记录(或者如果您没有域名,则可能需要购买域名),以便您的网站指向EC2实例的IP。

Also, I'm lost at "And I have a static IP which has 8GB RAM", by static IP do you mean the EIP? 另外,我迷失于“而且我有一个具有8GB RAM的静态IP”,通过静态IP您是指EIP吗? In any case, IP address has nothing to with RAM size though :) 无论如何,IP地址与RAM大小无关:)

All the best!! 祝一切顺利!!

You can still though achieve this by installing nginx and creating a re-write rule in nginx config as this: 您仍然可以通过安装nginx并在nginx config中创建一个重写规则来实现此目的,如下所示:

(1) install nginx (1)安装nginx

yum install nginx

(2) Create an A record for your static IP to point to some dns like lets say new-name.com (2)为您的静态IP创建一个A记录,以指向某些dns,例如让我们说new-name.com。

(3) Add the following config to your nginx config and replace old-name.com and new-name.com with aws url and domain name created in step 2 above respectively (3)将以下配置添加到您的nginx配置中,并分别用上述步骤2中创建的aws url和域名替换old-name.com和new-name.com

server {
    listen 80;
    listen 443 ssl;
    server_name www.old-name.com;
    return 301 $scheme://www.new-name.com$request_uri;
}

I hope that helps 希望对您有所帮助

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

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