10

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?

1 Answer 1

15

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.

3
  • 1
    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 :-) Aug 16, 2012 at 22:51
  • 1
    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. Aug 16, 2012 at 23:20
  • 1
    note this is available in httpd.conf file Aug 17, 2019 at 19:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .