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.

Im new to apache configuration and would be really glad if someone helped me with the following.Im running apache on a virtual private server, running the debian operating system.

In /etc/apache2/sites-available, i have two virtual hosts defined,site1.com.conf and site2.com.conf. In /etc/apache2/sites-enabled,i have a symlink to site1.com.conf . The virtual hosts are defined as follows:

site1.com.conf

<VirtualHost *:80>
  ServerAdmin admin@site1.com
  ServerName  site1.com
  ServerAlias www.site1.com site1.com
  DirectoryIndex index.html index.htm index.php
  DocumentRoot /var/www/site1
        <Directory /var/www/site1>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
  LogLevel warn
  ErrorLog /var/log/apache2/site1_error.log
  CustomLog /var/log/apache2/site1_access.log combined
  ServerSignature Off
</VirtualHost>

site2.com.conf

<VirtualHost *:80>
  ServerAdmin hostmaster@wharfage
  ServerName  site2.com
  ServerAlias www.site2.com site2.com
  DirectoryIndex index.html index.htm index.php
  DocumentRoot /var/www
  LogLevel debug
  ErrorLog /var/log/apache2/site2_error.log
  CustomLog /var/log/apache2/site2_access.log combined
  ServerSignature Off

  <Location />
    Options -Indexes
  </Location>

  Alias /favicon.ico /srv/site2/static/favicon.ico

  Alias /static /srv/site2/static
#  Alias /media  /usr/local/lib/python2.5/site-packages/django/contrib/admin/media

Alias /admin/media /var/lib/python-support/python2.5/django/contrib/admin/media 

  WSGIScriptAlias / /srv/site2/wsgi/django.wsgi

  WSGIDaemonProcess site2 user=samj group=samj processes=1 threads=10
  WSGIProcessGroup site2
</VirtualHost>

However, a strange thing is happening. Im able to navigate to www.site1.com as expected. It loads the content in /var/www/site which i have defined as the DocumentRoot in site1.com.conf. But if i navigate to www.site2.com,instead of loading index.html which is present in /var/www, which is defined as the DocumentRoot for site2.com.conf, as shown above, it loads the content in /var/www/site1. The url in the address bar remains www.site2.com. So, i have the following two questions :

Q.1) Why is www.site2.com showing the contents of /var/www/site1 when the DocumentRoot for it has been defined as /var/www ?

Q.2) Since, site2.com.conf does not have a symlink in sites-enabled, how come im able to navigate to www.site2.com ?

Sorry, if my questions sound noobish, but ill be really happy if someone could explain this.

Thank You.

share|improve this question

1 Answer 1

It doesn't matter what address you use. If the IP address is the same, you could use site3.com and still access site1. The first VirtualHost will be served for all hostnames that don't match any ServerName or ServerAlias. You need to symlink the site2.com.conf file (or use a2ensite) to be able to access it.

share|improve this answer
    
Thanks for the reply Tomas :). Your explanation is clear to me.I did a2ensite site2.com.conf in /etc/apache2/sites-available. That automatically created a symlink for that file in sites-enabled. I then did /etc/init.d/apache2 reload.But now when i navigate to www.site2.com, i get 404 Not Found . Any way to fix this ? –  qubit Nov 23 '09 at 20:42
    
That is likely because you have WSGIScriptAlias for '/' and so all requests going through to Django. In other words, you have configured it so that Django takes precedence other static index.html. You will have to be clearer about how you want it to work if you don't want that. –  Graham Dumpleton Nov 23 '09 at 22:23

Your Answer

 
discard

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