?
Solved

How to make this apache virtualhost working in Ubuntu?

Posted on 2012-09-13
4
Medium Priority
?
455 Views
Last Modified: 2012-09-14
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
Comment
Question by:Amber Bruelemans
  • 3
4 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 38397242
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
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 1000 total points
ID: 38397630
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 38397833
>     $ 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
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 38397900
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question