Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a domain foo.this.com I would like it to map to bar.that.com so I created a cname on the interface of my register. However, when I try to reach foo.this.com, it shows a 404 pointing to the IP of bar.that.com.

So my question is, what do I need to configure on my server (that hosts the web page of bar.that.com) to recognize foo.this.com?

thanks in advance.

share|improve this question
    
What if I have tons of cname, can I put them in a another file and include it in the config file of my web server? I use nginx but an answer about apache would be good too. –  peakty Nov 17 '09 at 5:16
add comment

4 Answers

It depends on what http daemon you are using.

If you are using Apache HTTPD with virtualhost entries, you most likely need to add a ServerAlias directive to the VirtualHost entry for your site.

<VirtualHost *:80>
    ServerName bar.that.com
    ServerAlias foo.this.com
    DocumentRoot /home/that.com
    ... snip ... 
</VirtualHost>
share|improve this answer
add comment

What you want to do goes under the term Name Based Virtual Hosting

Technically what is going on is that the web browser resolves bar.that.com to an IP address (e.g. 1.2.3.4). Then it sends an HTTP request to 1.2.3.4. The host does not normally know about the name which was used to address it.

An special feature of HTTP 1.1 however allows the browser to insert the host name into the HTTP header. A typical HTTP header looks like this:

GET / HTTP/1.1
Host: bar.that.com

The web server then decides according to the contents of the Host: header which pages to deliver. Of course you have to tell it how to decide in it's configuration. For Apache see here, but any modern web server will have something similar.

Name Based Virtual Hosting is widely used, everytime you hear the term Shared Hosting, think of Name Based Virtual Hosting. HTTP 1.1 is around long enough so that all browsers in use support it. Only very, very old browsers, like NCSA Mosaic, didn't support it.

share|improve this answer
add comment

If you're using IIS then you'll need to add host headers to the bar.that.com web site for foo.this.com

share|improve this answer
add comment

For nginx, if you want to have a directive handle more than one domain/subdomain, you can put them all in the server_name directive. For example,

server {
    listen 80;
    server_name foo.bar.com baz.foo.com bar.foo.com *.foo.com;
    [.......]
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.