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 2 sites on my server. One I access via my IP, x.x.x.x/site1. The other is a registered domain name, www.mysite.com.

Initially, I had only my /etc/apache/sites-available/default file available but when I tried loading either of the sites above I just got my /var/www/index.html output.

I included a new virtualhost for mysite.com with the following code:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/mysite
    <Directory />
            Options FollowSymLinks
            AllowOverride All
    </Directory>
    <Directory /var/www/mysite>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

Mysite.com only loads when default is disabled but then, x.x.x.x/site1 doesn't.

So, I enable the default virtualhost which has the following code:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

Now, x.x.x.x/site1 works but mysite.com does not - instead it loads the /var/www/index.html page.

I'm confused about what the issue is. I would appreciate some help.

share|improve this question

1 Answer 1

In order for a virtual domain to work it needs to know what host to map to. In your http request for the browser it sets a Host header like

Host: mysite.com

So apache will read that to figure out what vhost entry to use. You need to add something like

ServerName mysite.com www.mysite.com

To the mysite.com virtual host in the <VirtualHost *:80>

share|improve this answer

Your Answer

 
discard

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

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