如何将 HostGator 域指向 EC2 AWS

How to point HostGator domain to EC2 AWS

我们有一个现有的域名

(ex. webdev.com)

位于 hostgator 中,我们在 AWS 中有一个服务器。我们想使用从 hostgator

购买的域名

(webdev.com)

在我们的 AWS 服务器中。

我们所做的是,在 hostgator 中我们创建了一个 DNS (project1.webdev.com),该地址指向我们的 AWS 服务器(例如 150.12.1.0)。在我们的 AWS 中,我们将 project1 部署在端口 4000 下。

现在如果我们访问

project1.webdev.com

我们最终到达了默认的 Apache 页面。我们如何将它路由到我们的端口 4000,以便每次我们访问 project1.webdev.com 它都指向我们的

150.12.1.0:4000

项目。

这是我们的虚拟主机配置:

<VirtualHost *:4000>
ServerName project1.webdev.com
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/var/www/html/project1/web"

<Directory "/var/www/html/project1/web">
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      Allow from all
    </Directory>

ErrorLog ${APACHE_LOG_DIR}/4000-error_log
CustomLog ${APACHE_LOG_DIR}/4000-access_log common

我们已经查找了一些信息,但没有找到任何可能的解决方案。期待您的帮助。

谢谢

您混淆了与 IP 寻址有关的 DNS 和与 DNS 无关的端口。 DNS 仅处理人类可读名称和 IP 地址之间的转换。 DNS 不提供任何形式的规定来执行 "when a user wants to make an HTTP request use port 4000 instead of port 80".

之类的任务

如果您的服务正在侦听端口 4000 但您使用的是 HTTP 协议(​​默认情况下始终使用端口 80),那么您将需要通过以下方式之一处理此问题:

  • 要求所有 URL 明确指定端口 4000,例如:http://project1.webdev.com:4000
  • 更改您的 VirtualHost 定义以侦听端口 80 而不是 4000
  • 在 Apache 中为端口 80 添加一个新的 VirtualHost 定义,proxies all requests 到端口 4000

与您分享我们的解决方案。感谢@Bruce 帮助我们。正如他在上面的评论中所建议的那样,我们将创建一个移植到 80(这是 apache 的默认值)的虚拟主机。然后我们将80端口路由到我们具体的项目中。

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com
    ServerName project1.webdev.com
    ServerAdmin webmaster@localhost
    DocumentRoot "/var/www/html/project1/web"

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/project1-error.log
    CustomLog ${APACHE_LOG_DIR}/project1-access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

如果您有多个 DNS,只需创建端口 80 的另一个实例并路由到项目。

确保 HostGator 中的域名与您在虚拟主机中创建的 ServerName 匹配。