CentOS中Apache虚拟主机(virtualHost)设置在/home目录下的若干问题

在Ubuntu中安装LAMP是非常简单的意见事情。但是在CentOS中却遇到了很多问题。

首先是CentOS中必须手动配置iptables,把80端口开放出来,不然,是访问不到的,开放80端口在/etc/sysconfig/iptables增加:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

记得重启iptables,规则才会生效。

接下来就是配置VirtualHost遇到的问题了。问题有两个。

1.配置好Vhost.conf 

NameVirtualHost *:80

<VirtualHost *:80>
     ServerAdmin webmaster@example.com
     ServerName example.com
     ServerAlias www.example.com
     DocumentRoot /home/www/yourhost/
     ErrorLog /home/www/yourhost/logs/error.log 
   CustomLog
/home/www/yourhost/logs/access.log combined
</VirtualHost>

重启apache时候,会出现:

DocumentRoot [/home/www/yourhost/] don's exists 

目录的确是存在的。多上查找,后来知道是SELinux的原因:

SELinux is preventing the http daemon from reading users' home directories.

很多教程中在配置Apache的时候直接关闭了SELinux,这种做法是一劳永逸,但是安全性方面就不是那么好了(到底多不好就不知道了,我对SELinux也不甚了解)。

这个有解决方法,原理我也不清楚,可能是把一下限制开放吧,如果知道的朋友,请指出来:

setsebool -P httpd_enable_homedirs=1

这样就解决了会出现目录不存在的问题。

2.apr_sockaddr_info_get() failed yourhost

这个简单,直接在/etc/httpd/httpd.conf 增加一句:

NameServer yourdomain

这里要注意的是要在hosts文件中将yourdomain添加进去。

关于SELinux那块,可能存在错误的地方,毕竟我不熟悉。如果有说错的,请不吝指正,多谢。

原文地址:https://www.cnblogs.com/hui314/p/under_centos_apache_configure_notices.html