Logo 
Search:

Unix / Linux / Ubuntu Forum

Ask Question   UnAnswered
Home » Forum » Unix / Linux / Ubuntu       RSS Feeds

Apache Virtual Hosts

  Date: Dec 07    Category: Unix / Linux / Ubuntu    Views: 548
  

03262007 1404 GMT-6 DST

I need some help with apache virtual hosts.

Im trying out joomla and drupal but they need apache setup a certain
way. I use my local machine for development purposes. So, in
my /var/www/ I want to enable my client files to be virtual hosted.

My hang up is, Im not totally understanding how to configure this
option. The tutorials all talk about your url being a real url. Im just
wondering if I can end up with something like clientA.localhost,
clientB.localhost where client A & B are actual client site names like
Dale.localhost and MPORG.localhost.

Share: 

 

8 Answers Found

 
Answer #1    Answered On: Dec 07    

I use to have guy reporting to me that new that stuff so I didn't have to.&-(
Ted
It's 75 degrees in the Winter Wonderland!

 
Answer #2    Answered On: Dec 07    

03262007 1523 GMT-6 DST

82' here in Ok.

I found another tutorial that a guy shot me of IM. Im checking that out
now.

 
Answer #3    Answered On: Dec 07    

Im setting up my new system and Im having trouble setting up Virtual Sites.

httpd.conf
<VirtualHost *>
ServerName wadesmart
DocumentRoot /home/wadesmart/www
</VirtualHost>

default
NameVirtualHost *
<VirtualHost *>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
~ /// ~

</VirtualHost>

What Im missing... ???

 
Answer #4    Answered On: Dec 07    

I've done this before, but I don't have access at
this time to my home machine (where the setup examples
can be easily posted) so- here goes.

I found that in addition to editing the apache httpd.conf file, that a
host file entry (in /etc/hosts) was also required to achieve success.

Here are 4 links that should either get you started in the right
direction, or possibly even provide solution through their examples.

http://bobpeers.com/linux/apache_virtual_hosts.php
www.ubuntuproductivity.com/.../ubuntu-linux-virt\
ual-hosts-with-apache2/
linux.com/.../8202-how-to-set-up-apache-vi\
rtual-hosting
http://apptools.com/phptools/virtualhost.php

 
Answer #5    Answered On: Dec 07    

I checked the hosts file but there is nothing there to change.
I can access it now though wadesmart (machine name) but not localhost.
localhost still points to the apache root. Im not finding why that is.
Doc root points to my /home/wadesmart/www file so.. Im still missing
something.

 
Answer #6    Answered On: Dec 07    

Oh, I see what you mean. I'll check on this when I get home, my
xampp setup there might have the answer. (not 100% sure tho).

 
Answer #7    Answered On: Dec 07    

I no longer have that information.
But what I can remember now is that
in httpd.conf, I usually comment out the
default path (document root) of /var/www/

and replace it with a directory on my /home/userName location such
as /home/userName/public_html

editing the hosts file is for DNS resolution and can be quite
convenient if you're using named virtual hosting.

 
Answer #8    Answered On: Dec 07    

I once had this working on one of my "play" machines. Unfortunately this
configuration is long since wiped. However as this thread below is in
danger of running out of steam I have found my achieved notes from
backup DVD. They may help, although out of context they may not make
much sense.

My set up was to support both SSL (port 443) and standard HTML (port 80)
on the same server, but the principle is the same for multiple sites on
one server. Skip the certificate stuff if not needed.

You can do this is two ways: Multiple IP addresses on one server &
multiple Domain names (identified in the request header information)
using the same server IP address. These notes are for a single IP
address.

This may not be the best way of doing it. My notes may have got confused
in places (it did not work for me first time round, and I tried to keep
my notes in line with the eventual configuration, but I may not have
succeeded - I never rebuilt on a clean server to test these notes).

Because I no longer have the server build, I can't support these notes
if they do not work. Sorry. Nevertheless they might help.

--- o 0 o ---

Before configuring Apache, stop the server:
• sudo /etc/init.d/apache2 stop

To configure the Apache 2 server name (only needed if not registered in
DNS):
• sudo vi /ect/apache2/apache2.conf
append to end of file:
# ServerName
ServerName <servername.com>

Generate a self-signed SSL certificate
(NB. Self-signed SSL certificates are really only for testing, replace
it with one signed by a certification authority for the live server.)
• sudo apache2-ssl-certificate -days 365
Answer the questions:
Country Name (2 letter code) [GB]:GB
State or Province Name (full name) [Some-State]:UK
Locality Name (eg, city) []:xxx
Organization Name (eg, company; recommended) []:xxxx
Organizational Unit Name (eg, section) []:.
server name (eg. ssl.domain.tld; required!!!) []:xxxx.gotdns.com
Email Address []:xxx@...
(NB. To overwrite, "sudo apache2-ssl-certificate --force -days
365")

Enable the SSL port:
• sudo vi /etc/apache2/ports.conf
Edit to add "Listen 443" on the next line

Load the SSL module:
• sudo a2enmod ssl
(NB. If needed, the command to disable SSL is "sudo a2dismod
ssl")

WWW Directory structure
To make the directory structure
• cd /var/www
• sudo mkdir site-name-80
• sudo mkdir site-name-ssl
(Only needed if using SSL pages)

Add holding HTML pages to /var/www/site-name-80 & /var/www/site-name-ssl
Repeat the above steps for each web site needed.

Virtual Hosts (port 80)
Edit the default Web site configuration:
• sudo vi /etc/apache2/sites-available/default
Make the following edits to the file:
1. Edit the two lines to add "80" as follows (needed when SSL
sites are added):
NameVirtualHost *:80
<VirtualHost *:80>
...
</VirtualHost>
2. Edit the server administration email address:
ServerAdmin <valid email for the webmaster>
3. Also edit the correct path to the directory for the default site


Copy the default Web site configuration and customise it for each web
site needed:
• sudo cp /etc/apache2/sites-available/default
/etc/apache2/sites-available/sitename-80
• sudo vi /etc/apache2/sites-available/sitename-80
Edit as follows:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName sitename.co.uk
ServerAlias www.sitename.co.uk (http://www.sitename.co.uk/)
DocumentRoot /var/www/sitename-80
CustomLog /var/log/apache2/sitename-80-access.log combined
ErrorLog /var/log/apache2/sitename.com-error.log
</VirtualHost>

Mod rewrite
If needed we can force users to access sites with sensitive or private
content via SSL / https using "mod_rewrite".

First enable the module:
• sudo a2enmod rewrite

Then add the following to /etc/apache2/sites-available/sitename-80
RewriteEngine on
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^/directory(.*)$ https://%{site-name}/directory$1 [L,R]
RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 2

Create directory for pidfile; it may be missing
• sudo mkdir -p /var/run/apache2
• sudo chown -R www-data /var/run/apache2

N.B. If this section is being used out of context with the other steps
in this post, don't forget to restart apache
• sudo /etc/init.d/apache2 force-reload

Virtual Hosts SSL (port 443)
Copy a new configuration file for a SSL virtual server from the standard
(port 80) configuration file:
• sudo cp /etc/apache2/sites-available/sitename-80
/etc/apache2/sites-available/sitename-443

Edit the new configuration file for a SSL virtual server:
• sudo vi /etc/apache2/sites-available/sitename-443
Edit as follows:
NameVirtualHost *:443
<VirtualHost *:443>
(... edit the directories too...)

Also, in the same file:
Find the commented area which says "# Possible values include: debug,
info, notice, warn, error, crit..." and after this add:
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/apache.pem

Enable the new sites
Enable each new site (both 80 & 443) with the command:
• a2ensite <sitename>
Create a symbolic link to the new configuration file in the Site
Available folder:
• sudo ln -s /etc/apache2/sites-available/ssl
/etc/apache2/sites-enabled/ssl

Restart the server
Restart the web server:
• sudo /etc/init.d/apache2 restart

 
Didn't find what you were looking for? Find more on Apache Virtual Hosts Or get search suggestion and latest updates.




Tagged: