editing apache vhosts and ubuntu hosts file?
File: /etc/hosts
127.0.0.1 site1.local
127.0.0.1 site2.local
127.0.0.1 site3.local
File: /etc/apache2/apache2.conf
[...]
NameVirtualHost *:80
[...]
Files: /etc/apache2/sites-available/site{i}.local.conf (instead of {i} insert number: 1 or 2 or 3)
<VirtualHost *:80>
ServerName site{i}.local
ServerAdmin webmaster@localhost
DocumentRoot /var/www/site{i}
[...]
</VirtualHost>
In directory /etc/apache2/sites-enabled/ create symbolic links:
@site{i}.local.conf
Restart apache and have fun :)
Related videos on Youtube
Hailwood
I could tell you all about me... but I'd prefer to let my work do the talking for me!
Updated on September 18, 2022Comments
-
Hailwood over 1 year
I have just installed ubuntu (11.04).
I have installed apache/mysql/php etc.
I have a few sites sitting in
/var/www/site1 /var/www/site2 /var/www/site3
I want to be able to access these at
http://site1.local http://site2.local http://site3.local
So in my hosts file I have
127.0.0.1 site1.local 127.0.0.1 site2.local 127.0.0.1 site3.local
Then I have copied
/etc/apache2/sites-available/default
3 times.so now I have:
/etc/apache2/sites-available/site1 /etc/apache2/sites-available/site2 /etc/apache2/sites-available/site3
These all look like (with appropriate sitex names)
<VirtualHost site1.local> ServerAdmin webmaster@localhost DocumentRoot /var/www/site1 <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/site1/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost>
In the terminal I then call
sudo a2ensite site1 site2 site3 && sudo /etc/init.d/apache2 reload
Which seems to work, except only one of the vhosts works at the same time (including default), What am I doing wrong?
When I run the reload command I get- Reloading web server config apache2
apache2: Could not reliably determine the server's fully qualified domain name,
using 127.0.1.1 for ServerName
[Fri Apr 15 10:45:27 2011] [warn] NameVirtualHost *:80 has no VirtualHosts
-
Thomas Ward about 13 years@Hailwood: Are there any error messages or message output when you do
sudo /etc/init.d/apache2 reload
? -
Thomas Ward about 13 yearsWas curious, because that matches the same error(s) I get, which explains my interest in this question you asked.
-
Hailwood about 13 yearsWeird, I am surprised there is not an apache.stackexchange.com
-
Hailwood about 13 yearsbtw, just found serverfault so I have asked serverfault.com/questions/259890/… as well.
-
Thomas Ward about 13 yearsah very good. I'll watch here AND there :P
- Reloading web server config apache2
-
Hailwood about 13 yearsOne note is that the line suggested for
/etc/apache2/apache2.conf
was found in/etc/apache2/ports.conf
which is imported byapache2.conf