Tuesday, January 18, 2011

how to configure my cname on the server?

Hi all,

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.

  • 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>
    
    From kisoku
  • If you're using IIS then you'll need to add host headers to the bar.that.com web site for foo.this.com

    From joeqwerty
  • 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.

  • Hello,

    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;
        [.......]
    }
    
    From Michael

0 comments:

Post a Comment