亚马逊网络服务AWS:如何托管​​Java应用程序,分配自定义域名,自定义域名无法正常运行

时间:2018-02-17 16:07:31

标签: java amazon-web-services deployment subdomain web-deployment

我在这里托管了一个网站:http://testapp-test.us-west-2.elasticbeanstalk.com/someservlet.do

该网站包含index.jspsomeservlet

https://my.freenom.com内阁中,我试过:设置名称服务器并将网址转发设置为http://testapp-test.us-west-2.elasticbeanstalk.com。 前者不起作用:我在屏幕显示时设置了名称服务器,在尝试访问codingrecords.tk时,它只是空白。 然而,URL转发有效,并且确实显示主页面,但当我尝试访问http://codingrecords.tk/someservlet.do时,它仍会显示index.jsp消息。

我该如何解决?通过指定名称服务器,而不是URL转发?但那时它也不起作用..

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

3 个答案:

答案 0 :(得分:4)

好的,所以经过大量的谷歌搜索和尝试,我设法让它工作。我希望它能帮助未来的读者。

我在Internet上的自定义域中部署我的Java应用程序所做的工作:

  1. 在freenom.com获取免费域名
  2. 创建密钥对(不知道是否必要,以防万一):
    2.1。转到亚马逊网络服务 - 服务 - EC2 - 密钥对 - 创建密钥对

    enter image description here

    enter image description here

    enter image description here

    2.2为密钥选择一些key_name,在计算机上保存文件

  3. 在AWS上创建应用程序和环境

    3.1转到 Amazon Web Services - 服务 - Elastic Beanstalk - 创建新应用程序

    enter image description here

    enter image description here

    3.2继续创建新应用程序,单击“下一步”,除非被迫填写内容;选择tomcat作为网络服务器;当我们找到一个密钥标签的表单时 - 选择一个现有的密钥,其中包含您之前分配给它的名称。

  4. 选择一个名称 - 下一步 - 创建Web服务器 - 选择平台Tomcat - 下一步 - 上传.war文件 - 下一步 - 如果您不需要数据库,请单击下一步 - 设置EC2 key_name的密钥对 - 下一步 - 不要对环境标记做任何事情 - 下一步 - 下一步 - 启动

    3.3您的应用程序已着陆;您可以在Elastic Beanstalk仪表板上看到它,您可以在服务 - EC2 - 实例中看到运行环境:

    enter image description here

    1. 创建IP地址:

      4.0转到服务 - EC2 - 实例。检查IPv4 Public IP列。如果那里已有地址,请转到第5点。如果它已空,请转到4.1。

      4.1转到服务 - EC2 - 弹性IP enter image description here

      4.2点击分配新地址

      enter image description here

      4.3选择并点击操作 - 关联地址 - 选择您应用的实例 - 关联

      enter image description here

    2. 设置路线53

      5.1转到服务 - 路线53 enter image description here

      5.2转到托管区域

      enter image description here

      5.3点击创建托管区域

      enter image description here

      5.4将您网站的名称添加到右侧的表单中(例如,butterflies.com,somesite.edu,无论如何):

      enter image description here

    3. 出现了一个包含两个托管区域记录集的表格: NS SOA 记录集。

      5.5单击NS记录集并将中的粘贴名称服务器复制到您的注册设置中:

      enter image description here

      enter image description here

      enter image description here

      5.6转到服务 - Elastic Beanstalk ,找到您的应用程序 - 复制URL值:

      enter image description here

      返回Route 53,点击创建记录集。选择键入:A,别名:是,在别名目标中粘贴网址。点击创建

      enter image description here

      5.7单击创建记录集。设置名称:www。设置类型:CNAME。将值设置为your_site_name.your_domain(例如,butterflies.com),单击创建

      enter image description here

      1. 已经完成了!有可能,your_site_name正在运行。

答案 1 :(得分:1)

因此,您只需要1个公共路由53区域进行codingrecords.tk,然后您可以通过为Elastic Beanstalk为您提供的ELB创建ALIAS记录,为子域www创建Route 53资源记录集。

由于您确实为www.codingrecords.tk创建了一个路由53区域,我会删除该区域(www.codingrecords.tk),使用下面的名称服务器创建一个Delegation Name set,当您使用该名称时为codingrecords.tk创建Route 53区域。这样您就不需要在Registar更改NS记录。

dig @8.8.8.8 www.codingrecords.tk NS

; <<>> DiG 9.8.3-P1 <<>> @8.8.8.8 www.codingrecords.tk NS
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38463
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.codingrecords.tk.      IN  NS

;; ANSWER SECTION:
www.codingrecords.tk.   21599   IN  NS  ns-1363.awsdns-42.org.
www.codingrecords.tk.   21599   IN  NS  ns-2005.awsdns-58.co.uk.
www.codingrecords.tk.   21599   IN  NS  ns-62.awsdns-07.com.
www.codingrecords.tk.   21599   IN  NS  ns-657.awsdns-18.net.

;; Query time: 134 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Sun Feb 18 18:05:38 2018
;; MSG SIZE  rcvd: 177

没有用于codingrecords.tk的名称服务器

dig @8.8.8.8 NS codingrecords.tk

; <<>> DiG 9.8.3-P1 <<>> @8.8.8.8 NS codingrecords.tk
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 55760
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;codingrecords.tk.      IN  NS

;; Query time: 156 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Sun Feb 18 18:15:39 2018
;; MSG SIZE  rcvd: 34

答案 2 :(得分:1)

只需将最后一条记录中的名称更改为www.codingrecords.tk即可。应该让它发挥作用。如果它没有 - 那么请阅读下面的内容,看看还有什么不对。

由于这是弹性beanstalk,您应该为其配置ELB。您需要做的就是为www.codingrecords.tk添加A记录,将其配置为ELB的别名。

如果您希望http://codingrecords.tk也能正常工作,您还需要为它添加A记录(也可以为您的ELB添加别名)。但也见P.S.下面。不知道为什么它甚至对你有用 - 它在你上面的配置中没有出现,当我从我的机器上尝试时它并没有解决。很可能你在/ etc / hosts或你的本地DNS中有它,或其他类似的东西。

我相信CNAME记录也应该有用。但我从未尝试过。对我来说,在Route 53中,类型似乎是一个稍微好一点的选择,因为您仍然可以将其配置为别名(从而剥夺CNAME的所有好处),但AWS仍将为查询返回实际IP地址,从而节省最终用户名称解析的往返。

P.S。我也相信你的NS和SOA记录是针对codingrecords.tk的,而不是www.codingrecords.tk。虽然在您当前的配置中完全有效,但他们基本上说您拥有www.codingrecords.tk(以及它的子域),但不是codingrecords.tk。我不认为这是你的意图。

相关问题