Apache Virtual Hosts configuration

  • dyefade
  • Expert
  • Expert
  • User avatar
  • Posts: 712
  • Loc: UK

Post 3+ Months Ago

Hi,

I've been experimenting of late with Apache2 running on Ubuntu 6.10 and have got pages showing, php, mysql all working, which is great! But, I am having difficulty in getting my virtual hosts configuration correct. What I want, is for if a user types in http://www.apictureofmanchester.co.uk/ they go to my web root, (i.e. /var/www), and if they type in http://www.peterboroughinwinter.co.uk/ it takes them to a subdir of that directory, (e.g. /var/www/peterboroughinwinter.co.uk). I looked here: http://httpd.apache.org/docs/2.0/vhosts/examples.html, used the examples they gave, and now my /etc/apache2/sites-available/default page looks like:

Code: [ Select ]
# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /var/www/
ServerName www.apictureofmanchester.co.uk

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /var/www/peterboroughinwinter.co.uk
ServerName www.peterboroughinwinter.co.uk

# Other directives here

</VirtualHost>
  1. # Ensure that Apache listens on port 80
  2. Listen 80
  3. # Listen for virtual host requests on all IP addresses
  4. NameVirtualHost *:80
  5. <VirtualHost *:80>
  6. DocumentRoot /var/www/
  7. ServerName www.apictureofmanchester.co.uk
  8. # Other directives here
  9. </VirtualHost>
  10. <VirtualHost *:80>
  11. DocumentRoot /var/www/peterboroughinwinter.co.uk
  12. ServerName www.peterboroughinwinter.co.uk
  13. # Other directives here
  14. </VirtualHost>


... but both domains still point to /var/www !? Can anyone hint at what I'm doing wrong? I have not made any changes to /etc/apache2/httpd.conf - could this be the problem?

Thanks in advance for any responses!
Ben.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • dyefade
  • Expert
  • Expert
  • User avatar
  • Posts: 712
  • Loc: UK

Post 3+ Months Ago

Could a mode move this to somewhere it's likely to be seen? Maybe the Scripting forum or maybe the Linux one? Thanks.
  • Daemonguy
  • Moderator
  • Web Master
  • User avatar
  • Posts: 2700
  • Loc: Somewhere outside the box in Sarasota, FL.

Post 3+ Months Ago

OK, I have always added them to httpd.conf, though most of our virtual content is static. To use the modularity of sites-avail, yuo need to do it right.

You have to make an entry to site 1 in sites-available as well as one for site 2.

Then you have to link those entries in sites-enabled.

This resembles aliasing and linking.

Here's an example:
Code: [ Select ]
#FILE: /etc/apache2/sites-available/pictureofmanchester
NameVirtualHost www.pictureofmanchester.co.uk:80

<virtualhost www.pictureofmanchester.co.uk:80>
ServerAdmin <your info>
ServerName websiteA
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>
</virtualhost>
  1. #FILE: /etc/apache2/sites-available/pictureofmanchester
  2. NameVirtualHost www.pictureofmanchester.co.uk:80
  3. <virtualhost www.pictureofmanchester.co.uk:80>
  4. ServerAdmin <your info>
  5. ServerName websiteA
  6. DocumentRoot /var/www/
  7. <directory>
  8. Options FollowSymLinks
  9. AllowOverride None
  10. </directory>
  11. <directory /var/www/>
  12. Options Indexes FollowSymLinks MultiViews
  13. AllowOverride None
  14. Order allow,deny
  15. allow from all
  16. </directory>
  17. </virtualhost>


For the record, I would put that site in it's own directory (/var/www/picture), just for clarity.

Then you have to link that file in sites-enabled:

Code: [ Select ]
cd /etc/apache2/sites-enabled
sudo ln -s /etc/apache2/sites-available/pictureofmanchester .
  1. cd /etc/apache2/sites-enabled
  2. sudo ln -s /etc/apache2/sites-available/pictureofmanchester .


Issue a restart and it should work. Do the same for the second site.
  • webagent
  • Born
  • Born
  • webagent
  • Posts: 4

Post 3+ Months Ago

You should have the server IP in NameVirtualHost and the same for each virtualhost. I use this settings for my virtualhost:

<VirtualHost MyServerIP:80>
DocumentRoot /var/www/mypathtomysite
ServerName funbly.com
ServerAlias http://www.funbly.com
ErrorLog /var/log/apache2/mylogpath/error.log
CustomLog /var/log/apache2/mylogpath/access.log combined
</VirtualHost>

You can try this:

<virtualhost SERVER_IP:80>
ServerAdmin YourEmail@yourhost.dom
DocumentRoot /var/www
ServerName apictureofmanchester.co.uk
ServerAlias http://www.apictureofmanchester.co.uk
ErrorLog /var/log/apache2/apictureofmanchester/error.log
CustomLog /var/log/apache2/apictureofmanchester/access.log combined
</VirtualHost>

<virtualhost SERVER_IP:80>
ServerAdmin YourEmail@yourhost.dom
DocumentRoot /var/www/peterboroughinwinter.co.uk
ServerName peterboroughinwinter.co.uk
ServerAlias http://www.peterboroughinwinter.co.uk
ErrorLog /var/log/apache2/peterboroughinwinter/error.log
CustomLog /var/log/apache2/peterboroughinwinter/access.log combined
</VirtualHost>

You also must have index.html/htm/php (for apictureofmanchester.co.uk) in /var/www.

I hope this is ok for you.
  • Daemonguy
  • Moderator
  • Web Master
  • User avatar
  • Posts: 2700
  • Loc: Somewhere outside the box in Sarasota, FL.

Post 3+ Months Ago

He does not require the IP in the virtualhost directive.
  • dyefade
  • Expert
  • Expert
  • User avatar
  • Posts: 712
  • Loc: UK

Post 3+ Months Ago

Thank you both for your responses, this has been very useful. I'm a bit of a fraud as it was an academic exercise really, I only need one site for now. Sometime this year I intend to learn apache2 properly rather than the half-assed set-up I've been playing with.

Thanks again, B.

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 20 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.