• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 461
  • Last Modified:

How to make this apache virtualhost working in Ubuntu?

According to the docs https://help.ubuntu.com/10.04/serverguide/httpd.html i have done following, and that is almost how i do always in my Fedora, but Ubuntu looks like its not working.

a) DNS to IP

    $ echo "127.0.0.1  a" > /etc/hosts
    $ echo "127.0.0.1  b" > /etc/hosts

b) Apache virtualhost

    $ ls
    1  2  default  default.backup  default-ssl
    $ cat 1
    <VirtualHost *:80>
     ServerName a
     ServerAlias a
     DocumentRoot /var/www/html/a/public
     <Directory /var/www/html/a/public>
        #AddDefaultCharset utf-8
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
     </Directory>
    </VirtualHost>
   
    $ cat 2
    <VirtualHost *:80>
     ServerName b
     ServerAlias b
     DocumentRoot /var/www/html/b/public
     <Directory /var/www/html/b/public>
        #AddDefaultCharset utf-8
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
     </Directory>
    </VirtualHost>

c) load into Apache and restart the service
   
    $ a2ensite 1
    $ a2ensite 2
    $ a2dissite default
    $ /etc/init.d/apache2 restart
   
d) Browse the new 2 hosts

    $ firefox http://a


Does not work it goes always with `http://a` or `http://b` to `/var/www/html`

How do i fix it so that it goes to its own directory e.g: `http://a` goes to `/var/www/html/a/public` not `/var/www/html`?
0
Amber Bruelemans
Asked:
Amber Bruelemans
  • 3
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
Interesting question.  I tried it a slightly different way using the GUI on Ubuntu 8.04 but it did the same thing.  I think it should work but I haven't figured out how.
0
 
Dave BaldwinFixer of ProblemsCommented:
After a Lot of trial and error I got 'aaa' and 'bbb' sites working in subdirectories under '/var/www'.  I had to give them both their own IP addresses on my network, add them to the hosts file, and the last step was adding them to the 'interfaces' file.  I was not able to get them to work as additional sites under '127.0.0.1'.

This is something I have done with several '/home' directories but it took forever to realize that I had to add the new interfaces to the 'auto' list in '/etc/network/interfaces' in addition to listing them as 'eth0-6'.  This is what my virtual directory file 'aaa' in 'sites-available' looks like.

NameVirtualHost 10.202.46.98
<VirtualHost 10.202.46.98>
	ServerAdmin webmaster@localhost
	ServerName aaa
	DocumentRoot /var/www/aaa/
	<Directory /var/www/aaa/>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride None
		Order allow,deny
		allow from all
	</Directory>

	ErrorLog /var/log/apache2/error.log

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

	CustomLog /var/log/apache2/access.log combined
	ServerSignature On

</VirtualHost>

Open in new window

0
 
ahoffmannCommented:
>     $ echo "127.0.0.1  a" > /etc/hosts
>     $ echo "127.0.0.1  b" > /etc/hosts

ends up with a /etc/hosts containing (only):
127.0.0.1  b

maybe you need to rethink about generating your /etc/hosts ;-)
0
 
Dave BaldwinFixer of ProblemsCommented:
Thanks for the points.  Note that when you do it that way, you can add it to the hosts file on any computer in your network and access it by name.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now