使用Apache设置服务器和子域

我有一个主域www.example.com

我想有这样的子域

www.pictures.example.com

我(想)可以select:

  1. 使用虚拟服务器将不同的地址(即主域和子域)匹配到同一个Apache服务器进程
  2. 使用两个独立的Apache服务器(尽pipe在同一台机器上)来独立处理请求

我的问题是:

  1. 上面1和2有什么优点和缺点?
  2. 我怎样才能实现1或2(即上述每个备选scheme需要执行哪些步骤)?

你在这里实际上没有select。 如果你运行两个独立的Apache实例,他们不能同时抓取端口80.使用虚拟主机是最好的解决scheme。

将以下内容添加到您的apacheconfiguration中:

NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /var/www/example.com ServerName example.com ServerAlias www.example.com # the remainder of your example.com configuration goes here </VirtualHost> <VirtualHost *:80> DocumentRoot /var/www/pictures.example.com ServerName pictures.example.com ServerAlias www.pictures.example.com # the remainder of your pictures.example.com configuration goes here </VirtualHost>