如何在一个文件中设置多个虚拟主机

how to setup multiple vhost in one file

我从 Fedora 移动到 ubuntu 16.04.

在 Fedora 中,我可以在一个文件中列出无穷无尽的虚拟主机。在 ubuntu 中,我必须为每个虚拟主机创建一个新文件。我已经有了包含所有虚拟主机的列表。在 ubuntu 中有什么方法可以做到这一点?

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerAdmin admin@apecenergy
    DocumentRoot /var/www/html/apecenergy.co.uk/public_html
    ServerName www.apecenergy.co.uk
    ServerAlias apecenergy.co.uk 
    ErrorLog "/var/log/httpd/apecenergy-error_log"
    CustomLog "/var/log/httpd/apecenergy-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin admin@apecenergy
    DocumentRoot /var/www/html/plumbing_sites/crouchendplumber.co.uk/public_html
    ServerName www.crouchendplumber.co.uk
    ServerAlias crouchendplumber.co.uk 
</VirtualHost>

那只是 ubuntu 的 apache 快捷方式组织。它会以同样的方式工作。您可以将包含多个虚拟主机的一个长文件保存到 filename.conf 下的 sites_available 文件夹中,然后一次启用它们。

sudo a2ensite filename

虽然一开始这样做很方便,但如果您花时间将它们分开,那么在较长的时间里您会过得更好运行。