How to point HostGator domain to EC2 AWS

2.1k Views Asked by At

We have an existing domain name

(ex. webdev.com)

located in hostgator and we have a server in AWS. We wanted to use the domain name that we bought from hostgator

(webdev.com)

in our AWS server.

What we did was, in hostgator we created a DNS (project1.webdev.com) and the address is pointing to our AWS server(ex 150.12.1.0). In our AWS, we deploy the project1 under port 4000.

Now if we access the

project1.webdev.com

we end up to the default apache page. How could we route it to our port 4000 so that everytime we access project1.webdev.com it pointed to our

150.12.1.0:4000

project.

here is our virtual host config:

<VirtualHost *:4000>
ServerName project1.webdev.com
ServerAdmin [email protected]
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

We have looked for several information but we did not find any possible solution. Looking forward for your help.

Thanks

2

There are 2 best solutions below

3
On BEST ANSWER

You're confusing DNS, which has to do with IP addressing, with ports, which have nothing to do with DNS. DNS only deals with converting between human-readable names and IP addresses. DNS does not provide any sort of provision to perform a task like "when a user wants to make an HTTP request use port 4000 instead of port 80".

If your service is listening on port 4000 but you're using the HTTP protocol (which always uses port 80 by default) then you will need to deal with this in one of the following ways:

  • Require all URL's to explicitly specify port 4000, for example: http://project1.webdev.com:4000
  • Change your VirtualHost definition to listen on port 80 instead of 4000
  • Add a new VirtualHost definition in Apache for port 80 that proxies all requests to port 4000
0
On

Sharing you the solution we made. Thanks to @Bruce for helping us out. As what he suggested in the comments above, we will create a virtual host porting to 80(which is the default of apache). Then we will route the port 80 to our specific project.

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

If you have multiple DNS just create another instance of port 80 and route to the project.

Make sure that the Domain name in HostGator matches with the ServerName you created in the virtual host.