I'm on an EC2 instance and have a domain domain.com linked to the EC2 nameservers and it happily is serving my pages if I type domain.com in the URL.

However when the page is served it resolves the url to:

Using apache I've set up the following VirtualHost, following examples provided at http://httpd.apache.org/docs/2.0/dns-caveats.html

Listen 80


DocumentRoot /var/www/html/directory
ServerName domain.com

# Other directives here ...

<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=290304000, public"

However I'm not getting any changes to how the URL is displayed.

This is the only VirtualHost configured on this site and I've confirmed its the one being used as I've managed to break it a number of times whilst experimenting with the configuration.

The route53 entries I have are:

domain.com A
domain.com NS ns-11.awsdns-11.com 
domain.com SOA ns-11.awsdns-11.com. awsdns-hostmaster.amazon.com. 1 1100 100 1101100 11100
  • The pages are served if you type domain.com, but it is "resolving" to XYZ "However I'm not getting any changes to how the URL is displayed." - Are you being redirected to XYZ, which is causing the URL to change?? – MrWhite Feb 9 '14 at 10:27
  • ...what do you mean by "resolving"? – MrWhite Feb 9 '14 at 11:48
  • i type domain.com and it directs me to 1111.11.11.11/directory/file.php. By resolve I just mean it redirects me to the url, probably just my poor terminology. I'm new to this type of work – sapatos Feb 9 '14 at 23:19
  • If you are being redirected to a different URL then I can't see how this relates to the VirtualHost/DNS settings mentioned - this would seem to be unrelated? – MrWhite Feb 9 '14 at 23:32
  • the location it directs me to is correct, however I'd like it to remove the 1111.11.11.11 and replace it with domain.com/... – sapatos Feb 10 '14 at 4:17

First, use <VirtualHost *:80> instead of <VirtualHost>. That way your virtual host applies no matter what the IP address of your server is.

Second, you need to issue a redirect if the host name isn't what you expect. I would recommend having two virtual hosts. The first is the default one for any unexpected domain names or IP addresses. It can issue a redirect to the correct domain name. The second one should be the one for your domain name. Something like:

<VirtualHost *:80>
    ServerName localhost.localdomain
    Redirect permanent / http://domain.com/

<VirtualHost *:80>
    ServerName domain.com
    DocumentRoot /var/www/html/directory

    # Other directives here ...
| improve this answer | |

You'll need to set up a DNS record on the server - an A record using the IP address as the destination/target.

As an example, in your VirtualHost file, you should have something like:-

<VirtualHost *:80>
ServerName www.domain.com
ServerAlias domain.com
DocumentRoot "/var/websites/domain/"
ErrorLog "/var/websites/domain/logs/error.log"
CustomLog "/var/websites/domain/logs/access.log"

Obviously the above needs amending to the relevant paths on your server accordingly based on how you have it set up (you may need to create the necessary directories if they don't already exist).

Then you'd need to restart the server with service httpd restartfor the changes to take affect. Whether this differs on an EC2 instance I'm unsure, but this is what is needed on an Apache server.

| improve this answer | |
  • thanks Geoff, I've tried the same and I'm getting a '404 not found'. On EC2 I've got an A record in my route53 record set pointing at domain.com. Is this the DNS record you mean. I wasn't sure if you meant a DNS record on the actual server it's running on or the route53 server? – sapatos Feb 9 '14 at 10:06
  • it seems to only work if the ip address is in the VirtualHost tag – sapatos Feb 9 '14 at 10:09
  • Yes, the A record needs to be created in Amazon's DNS service route 53. Can you confirm what DNS records you have currently set up? – zigojacko Feb 9 '14 at 10:35
  • updated with records. I notice that I specified the name as domain.com not www.domain.com. I remember this being recommended and I tried adding some www.domain.com entries in case that was the fix and it didn't work. – sapatos Feb 9 '14 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.