Apache虚拟主机和子域名

我正在尝试创build一个项目我正在工作的子域, projectx.cairocubicles.com ,这个url指向另一台服务器比托pipewww.cairocubicles.com子域名指向的服务器已经安装了以下虚拟主机的apache:

<VirtualHost *:80> # Admin email, Server Name (domain name) and any aliases ServerAdmin [email protected] ServerName www.project1.cairocubicles.com # Index file and Document Root (where the public files are located) DirectoryIndex index.html index.php DocumentRoot /home/project1/web/public <Directory /home/project1/web/public> Options Indexes FollowSymLinks AllowOverride All AcceptPathInfo On Order allow,deny Allow from all </Directory> # Custom log file locations LogLevel warn ErrorLog /home/project1/web/log/error.log CustomLog /home/project1/web/log/access.log combined </VirtualHost> 

但现在浏览到project1.cairocubicles.com时,我得到一个不同的网站(虚拟主机列表中的另一个网站)。 我也尝试更改ServerName www.project1.cairocubicles.comServerName project1.cairocubicles.com但后来我得到了403 Forbidden错误。 任何线索?

谢谢。

只是在黑暗中快速拍摄,但这可能是一个SELinux问题。 当你去的网站,你已经configuration为ServerName,什么都显示在网站特定的日志? /var/log/http/error.log中是否显示任何内容?

– 确保在configuration中进行了任何更改后,执行重新启动或重新加载apache2 / httpd

– 确保/ home / project1 / web / public存在,权限是664(用-Rrecursion执行)

– 确保文件的所有者和组是apache2 / httpd(取决于发行版),通常是用户标识33

– 确保project1.cairocubicles.com指向的IP地址是正确的

– 我通常避免www。 子域与现有的子域(不是技术上的原因,它只是看起来凌乱)

– 为了testing,创build一个名为phpinfo.php的文件,并且只包含以下内容

  <?php phpinfo(); ?> 

并只加载(所以http://project1.cairocubicles.com/phpinfo.php

– 您需要确保您已经修改了文件夹上的所有权和组信息。 尝试以下命令(展开上面的第3点):

 sudo chown apache2 /home/project1/public -R 

 sudo chgrp apache2 /home/project1/public -R 

如果命令说用户apache2不存在,则用httpdreplace它。 如果apache2进程(以用户apache2启动)无法读取/执行文件,则可能会出现错误(即禁止403)。

解决这个问题的另一个方法是将你的用户添加到apache2组中。 这虽然是正确设置的一点点复杂

尝试:

  ServerName project1.cairocubicles.com
 ServerAlias www.project1.cariocubicles.com

确保apache运行的用户具有对/ home / project1 / web / public目录的读取权限

如果一个域没有被列为ServerName或ServerAlias,它将从第一个定义的VirtualHost中加载。 这就是为什么在第一种情况下,你最终看到了错误的网站。

更改您的ServerName后,您可能正在加载正确的网站,但现在您有权限或内容的问题。 检查错误日志,访问日志和文件系统权限。 除此之外,之前的海报提到SELinux是一个可能的问题。

所以现在的工作时,我给/ home / userx的主目录一个o + x权限,这是安全的,为什么它需要执行权限的每个人

我需要确保我修改了文件夹上的所有权和组信息,使用以下命令:chown apache2 / home / project1 / public -R和chgrp apache2 / home / project1 / public -R如果命令说用户apache2不存在,用httpdreplace它。 这就是为什么它不在home目录(由你的用户所拥有)和/ var / www目录(由apache2拥有)中工作的原因。 我build议在/ var / www /指向您的主目录中创build一个符号链接。 这是标准的事情。 (更容易让别人看到发生了什么)