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 want to host two different sites on the same IP, same server, and same domain using Apache2 on Ubuntu Linux. Let's say I have the following directories which represent sites that will serve content:

/srv/www/blog/          #for the blog
/srv/www/mainsite/      #for the main site

I want to set up Apache2 so that the following applies:

  1. When a user visits http://mysite.com/ they are served content from /srv/www/mainsite/.
  2. When a user visits http://mysite.com/blog, they are served content from /srv/www/blog/.

I had thought I was going to be setting up multiple virtual hosts, but only seems to apply for distinct domains and/or IPs. What do I need to do in my apache2 configuration to achieve the above functionality?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Inside your <VirtualHost>:

DocumentRoot /srv/www/mainsite
<Directory /srv/www/mainsite>
    Order Allow,Deny
    Allow from all
</Directory>

Alias /blog /srv/www/blog
<Directory /srv/www/blog>
    Order Allow,Deny
    Allow from all
</Directory>

Ignore the directory blocks if you already have one that covers /srv/www - I just put them in to make it clear that you'll need Apache's access controls allowing access to both.

share|improve this answer
    
Thanks for the quick response! If this works, I'll be quite grateful and will feel a little silly that I didn't figure it out myself :-) –  Ben McCormack Aug 16 '12 at 22:51
    
That worked! Another thing I had to do was delete the extra virtual hosts files that I had created for the same domain. I kept thinking I had a problem in my new virtualhost setup when really I just had too many files. –  Ben McCormack Aug 16 '12 at 23:20
add comment

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.