Changes

Jump to navigation Jump to search

Coral: apache vhosts

10,365 bytes added, 13:35, 12 November 2011
Created page with "<div id="top" style="margin:0;padding: 0px 0px 0px 5px; color: #000; background-color: #FFFFEB; border: 1px solid darkslateblue;"><span id="top" style="margin:0;padding: 0px;font..."
<div id="top" style="margin:0;padding: 0px 0px 0px 5px; color: #000; background-color: #FFFFEB; border: 1px solid darkslateblue;"><span id="top" style="margin:0;padding: 0px;font-size:12px">'''''Coral'' :'''&nbsp; [[Coral: apache intro|Apache]] | [[Coral: apache basic configuration|Apache Basic Configuration]] | [[Coral: apache vhosts|Apache Vhosts]] | [[Coral: apache ssl|Apache - SSL]] | [[Coral: apache server cert self signed|Apache - Server Certificate Self-Signed]] | [[Coral: apache free server cert|Apache - Free Server Certificate]]</span></div>

{|style="margin-top:5px;"
|-valign="top"
|
<span style="margin-bottom:5px;font-size:25px;color: #31799F;">Apache Vhosts</span>

The Uniform Server is configured for name-based virtual hosting. This allows you to run any number of web sites from a single IP address. Each domain-name you host must first be registered and an “A” record created on a DNS server. This “A” record translates the domain-name to your IP address.


'''Note:''' For testing, “A” records are simulated using a PC's hosts files.

__TOC__

|
{| cellpadding="0" cellspacing="0" style="margin-left:6px;margin-bottom:5px;padding-left:6px;padding-right:6px;font-size:11px;background-color: #FFFFEB;border: 1px solid darkslateblue;"
|-
|colspan="2" style="font-weight:bold;"| UniServer&nbsp;8-Coral
|-
|&nbsp;||[[Coral: Introduction|Home]]
|-
|&nbsp;||[[Coral: start quick start|Quick Start]]
|-
|&nbsp;||[[Coral: general intro|General]]
|-
|<span style="font-size: 14px;">»</span>||[[Coral: apache intro|Apache]]
|-
|&nbsp;||[[Coral: mysql intro|MySQL]]
|-
|&nbsp;||[[Coral: php intro|PHP]]
|-
|&nbsp;||[[Coral: msmtp intro|MSMTP]]
|-
|&nbsp;||[[Coral: cron intro|CRON]]
|-
|&nbsp;||[[Coral: dtdns intro|DtDNS]]
|-
|&nbsp;||[[Coral: dbbackup intro|Db Backup]]
|-
|&nbsp;||[[Coral: perl intro|Perl]]
|-
|&nbsp;||[[Coral: index main|Main Index]]
|}
|}

==Features==
The main features of The Uniform Server’s Vhost configuration menu are:

* Include separate log files and server alias
* Auto enable when first vhost created
* Auto disable when last vhost deleted
* Port tracking follows main server port (defaults to port 80)
* Writes host name to Windows hosts file when vhost created
* Deletes host name from Windows hosts file when vhost deleted

==Overview==
Vhosts are configured using a separate configuration file UniServer\usr\local\apache2\conf\extra\'''httpd-vhosts.conf'''.

This file requires enabling in Apache’s main configuration file UniServer\usr\local\apache2\conf\'''httpd.conf'''

{|
|-
|
Search this file for the following line:< br />
<pre>
#Include conf/extra/httpd-vhosts.conf
</pre>
|
Remove the hash "#" to enable as shown below:< br />
<pre>
Include conf/extra/httpd-vhosts.conf
</pre>
|}
Note: The above is automatically performed when using The Uniform Server’s Vhost configuration menu.

'''''[[#top | Top]]'''''
===Inform Apache to use Vhosts===

Apache requires the directive '''NameVirtualHost address:port''' which instructs it to use virtual hosts and resolve an address on the specified port. The Uniform Server uses '''*:80''', where the * is a wildcard meaning use all addresses. Port 80 is the standard web server listening port. This can be changed if required, for example, to port 8080.

A separate '''NameVirtualHost''' directive is required for each different port used. These NameVirtualHost directives must have a corresponding listening directive. The Uniform Server’s Vhost configuration file contains the following block:

{|
|-
|
<pre>

#--US_START--------------Do not remove
NameVirtualHost *:80
#--US_END----------------Do not remove

</pre>
|
The "Do not remove" Lines are used by The Uniform Server to locate the block and insert lines as appropriate.<br />
The NameVirtualHost directive has a matching Listen directive Listen 80 located in the main configuration file
so it is not required in this configuration block.
|}

However, adding a virtual host that uses port 8080, a listen directive is required. The configuration block becomes:

{|
|-
|
<pre>
#--US_START--------------Do not remove
Listen 8080
NameVirtualHost *:80
NameVirtualHost *:8080
#--US_END----------------Do not remove
</pre>
|
The main configuration file (httpd.conf) does not contain a Listen 8080 directive and it is required and added to this configuration block along with the NameVirtualHost directive.


Note: These are automatically added when using The Uniform Server’s Vhost configuration menu.
|}

'''''[[#top | Top]]'''''
===Adding a Vhost===

Each virtual host requires a separate configuration block. These blocks inherit their configuration from the main configuration file httpd.conf. Specifying an Apache directive in a Vhost block overrides that of the main configuration file. The advantage of this inheritance is to reduce number of Apache directives required for each Vhost. The absolute minimum required is to specify a '''DocumentRoot''' and '''ServerName'''.


Apache resolves a Vhost by matching its port and ServerName. On finding a match, the server's content is fetched from the folder specified by DocumentRoot. If it cannot find a match, it uses the first Vhost defined (the default). Note: to avoid conflicts, Apache uses a '''_default_''' directive for the address of this first virtual host.


'''Example:''' to add a virtual host for fred.com on port 8080 and to serve content from folder UniServer\vhosts\fred, the minimum configuration required is:

{|
|-
|
<pre>
#--US_START--------------Do not remove
Listen 8080
NameVirtualHost *:80
NameVirtualHost *:8080
#--US_END----------------Do not remove

<VirtualHost _default_:80>
DocumentRoot C:/Coral/UniServer/www
ServerName localhost
</VirtualHost>

<VirtualHost *:8080>
DocumentRoot C:/Coral/UniServer/vhosts/fred
ServerName fred.com
</VirtualHost>
</pre>
|
The default Vhost maps to The Uniform Server’s folder www. If you wish, this can be changed as well as the server name.


The new Vhost fred.com maps to folder UniServer\vhosts\fred. This can be any folder you wish. All vhost root folders are created in the folder '''vhosts'''. This is not a strict requirment, but it is provided for portability (as when using a USB memory stick).


Note: Port 8080 is shown as an example. Generally all Vhosts would use the standard port 80.
|}

'''''[[#top | Top]]'''''
===Vhost additional Apache directives===
Other Apache directives can be included in a Vhost block. Common directives are shown in this example block:

{|
|-
|
<pre>

<VirtualHost *:80>
ServerAdmin webmaster@fred.net
DocumentRoot C:/Coral/UniServer/vhosts/fred_net
ServerName fred.net
ServerAlias www.fred.net *.fred.net
ErrorLog logs/fred.net-error.log
CustomLog logs/fred.net-access.log common
</VirtualHost>

</pre>
|
'''ServerAlias''' Allows you to access the server using sub-domains. Each sub-domain must have a corresponding DNS entry.


Each Vhost can have a separate '''ErrorLog''' and '''CustomLog''' log file. If you do not specify these log files, the main server log files are used.


'''Note:''' Separate log files will eat into your file allocation resources, depending on the total number of Vhosts you wish to host. This may become an issue .
|}

==Apache Vhosts==
This menu allows you to quickly create virtual host blocks.

<span style="padding:6px;background-color:#99FFFF"> '''UniController:''' Server Configuration > Apache > Apache Vhosts</span>

{|
|-
|
Creating a Vhost requires only two form entries, a server root folder and a host name. After entering these, click the confirm button. All other directives are optional, and are automatically filled in with values based on the above two form entries. Clicking the Create Vhost button creates the root folder if it does not exist. A Vhost is created in the Vhost configuration file and an entry is written to your PC’s host file. Here is a summary of the steps:

* '''A3)''' Either replace''' ***''' with the folder name you wish to use as your server root folder or click '''Select Folder''' button and navigate to an existing folder and select it.
* '''A4)''' Enter your server name (host name). This is the domain name you registered with a registrar, for example '''fred.com'''. It is the name you enter in a browser to access your web site (excluding the '''<nowiki>http://</nowiki>''' part).
* '''A13)''' Click the '''Confirm''' button. This enables the greyed out buttons and fills in form fields with selected values for other Apache directives. Change or delete these as appropriate.
* '''A10)''' Click '''Create Vhost''' button to create your virtual host.

'''Note 1:''' After creating a Vhost you '''must restart''' your Apache server otherwise Apache will not recognise the new configuration.

'''Note 2:''' For detailed information see [[Coral: apache vhosts|Apache Vhosts]]
|
[[Image:Coral_apache_vhosts_1.gif]]
|}

'''''[[#top | Top]]'''''
==Vhost Configuration Menu Example==

For clarity following example shows Vhost form filled in and the corresponding Vhost block created in the configuration file for host name fred.com and server root folder '''fred'''.

{|
|-
|
The block created in httpd-vhosts.conf

<pre>
<VirtualHost *:80>
ServerAdmin webmaster@fred.com
DocumentRoot C:/UniServer/vhosts/fred
ServerName fred.com
ServerAlias www.fred.com *.fred.com
ErrorLog logs/fred.com-error.log
CustomLog logs/fred.com-access.log common
</VirtualHost>
</pre>

The entry created in host file

<pre>
127.0.0.1 fred.com
</pre>

Note: An entry will be created in the List of Hosts (B1). After restarting Apache and returning to this menu you can click an entry. Clicking an entry enables the greyed out buttons, allowing you to perform the following tasks:

* '''A9)''' The Virtual host setup form is filled in allowing you to edit the Vhost. Click the '''Update Vhost''' button to apply your modification.
* '''B2)''' To remove a Vhost, click the '''Delete Vhost''' button. It deletes the Vhost block from the configuration file and removes the entry in the Hosts file. The root folder and all its content are deleted, however you are requested to confirm this action before it is implemented.
* '''B3)''' '''View In Browser''' opens default browser and displays the Vhost selected.
|
[[Image:Coral_apache_vhosts_2.gif]]
|}

'''''[[#top | Top]]'''''

----

[[Category: Uniform Server 8-Coral]]

Navigation menu