Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

After you’ve configured your Linux machine with multiple IP addresses,
setting up Apache to serve them as different websites is simple. You need
only put a VirtualHost directive in your apache2.conf file for each of


the addresses you want to make an independent website:


Click here to view code image
<VirtualHost 212.85.67.67>
ServerName gnulix.org
DocumentRoot /home/virtual/gnulix/public_html
TransferLog /home/virtual/gnulix/logs/access_log
ErrorLog /home/virtual/gnulix/logs/error_log



Use the IP address, rather than the hostname, in the VirtualHost tag.


You can specify any configuration directives within the
tags. For example, you might want to set AllowOverrides directives
differently for virtual hosts than you do for your main server. Any directives
that aren’t specified default to the settings for the main server.


Name-Based Virtual Hosts


Name-based virtual hosts enable you to run more than one host on the same
IP address. You must add the names to your DNS record as CNAMEs of the
machine in question. When an HTTP client (web browser) requests a
document from your server, it sends with the request a variable indicating the
server name from which it’s requesting the document. Based on this variable,
the server determines from which of the virtual hosts it should serve content.


Name-based virtual hosts require just one step more than IP address-based
virtual hosts. You must first indicate which IP address has the multiple DNS
names on it. This is done with the NameVirtualHost directive:


Click here to view code image
NameVirtualHost 212.85.67.67


You must then have a section for each name on that address and set the
configuration for that name. As with IP-based virtual hosts, you need to set
only those configurations that must be different for the host. You must set the
ServerName directive because it is the only thing that distinguishes one
host from another:


Click here to view code image
<VirtualHost 212.85.67.67>
ServerName bugserver.gnulix.org
ServerAlias bugserver

Free download pdf