在CentOS中指定Apache2虚拟主机的位置

我习惯于Ubuntu,那里有一个特殊的文件来包含虚拟主机。 但我得到的印象是,在CentOS中,虚拟主机在主configuration文件中列出。

任何人都可以确认吗?

编辑 – 试过这个,它不工作:

添加到httpd.conf

<VirtualHost *:80> ServerName example.com ErrorLog /var/www/example_apache_errors.log DocumentRoot /var/www/html/example <Directory /var/www/html/example/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> </VirtualHost> 

它不起作用。 我在/var/www/html/example/index.html创build的testing页面没有显示出来。 相反,/var/www/html/index.html的默认页面正在显示。

编辑:之前有人问,是的,我重新启动后,configuration更改的Apache。

编辑:

NameVirtualHost *:80在configuration文件中被默认注释掉,我没有取消注释。 我相信这是问题所在。

但是我决定使用基于IP的方式,像这样:

 <VirtualHost 69.175.xxx.xxx:80> ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example/ # etc. etc. </VirtualHost> 

这是工作。 我们有5个IP,所以希望我可以用这个方法在将来分配别人。

你知道你可以坚持像这样的东西:

 Include conf.d/*.conf Include sites-enabled/*.conf 

进入/etc/httpd/conf/httpd.conf,运行“mkdir -p /etc/httpd/ sites-enabled / etc / httpd / sites-available”,得到类似Ubuntu的Ubuntu目录结构,对吧?

更新(来自评论中的信息):

您还应validation是否已打开端口80的NameVirtualHosts。

由于Centos具有Include conf.d/*.conf 。conf,所以我把我的configuration放在那里。 不过,我通常使用NameVirtualHost *:80来configurationconf.d/00_NameVirtualHost.conf 。 我猜你没有设置在你的Apacheconfiguration。