首页 > 解决方案 > 添加新虚拟主机时 Apache 服务器无法启动

问题描述

我目前在运行 Apache2 的 Linode 上有一个 CentOS 7 服务器,其中有两个域指向它。我通过在 /etc/httpd/conf.d/vhost.conf 中配置基于名称的虚拟主机来实现这一点

这效果很好,但是...

出于某种原因,当我向该文件添加第三个虚拟主机时,apache 拒绝启动。我已经在 /var/www/html/... 中创建了所有适当的文件夹,并具有适当的权限(apache.apache)。但是 Apache 仍然拒绝启动。下面是我的 vhost.conf 文件的示例和来自 apache 的错误日志。我错过了什么步骤?

这是我的 vhost.conf ......

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@domain1.com
    ServerName domain1.com
    ServerAlias www.domain1.com
    DocumentRoot /var/www/html/domain1.com/public_html/
    ErrorLog /var/www/html/domain1.com/logs/error.log
    CustomLog /var/www/html/domain1.com/logs/access.log combined
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@domain2.com
    ServerName domain2.com
    ServerAlias www.domain2.com
    DocumentRoot /var/www/html/domain2.com/public_html/
    ErrorLog /var/www/html/domain2.com/logs/error.log
    CustomLog /var/www/html/domain2.com/logs/access.log combined
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@domain3.com
    ServerName domain3.com
    ServerAlias www.domain3.com
    DocumentRoot /var/www/html/domain3.com/public_html/
    ErrorLog /var/www/html/domain3.com/logs/error.log
    CustomLog /var/www/html/domain3.com/logs/access.log combined
</VirtualHost>

这是我从 apache 得到的错误...

Jan 16 18:40:30 dribrats systemd[1]: Starting The Apache HTTP Server...
Jan 16 18:40:30 dribrats httpd[19023]: AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/httpd/conf.d/vhost.conf:1
Jan 16 18:40:30 dribrats httpd[19023]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using xxxx::xxxx:xxxx:xxxx:xxxx. Set the 'ServerName' directive globally to suppress this message
Jan 16 18:40:30 dribrats systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Jan 16 18:40:30 dribrats kill[19024]: kill: cannot find process ""
Jan 16 18:40:30 dribrats systemd[1]: httpd.service: control process exited, code=exited status=1
Jan 16 18:40:30 dribrats systemd[1]: Failed to start The Apache HTTP Server.
Jan 16 18:40:30 dribrats systemd[1]: Unit httpd.service entered failed state.
Jan 16 18:40:30 dribrats systemd[1]: httpd.service failed.

标签: apachecentos7virtualhosts

解决方案


好的,我已经想通了。问题源于我对第三个域的新文件夹的权限。我没有设置正确的权限。运行以下命令解决了我的问题。

sudo chown apache:apache -R /var/www/html/example.com/

cd /var/www/html/example.com/
find . -type f -exec sudo chmod 0644 {} \;
find . -type d -exec sudo chmod 0755 {} \;
sudo chcon -t httpd_sys_content_t /var/www/html/example.com -R
sudo chcon -t httpd_sys_rw_content_t /var/www/html/example.com -R

然后重启apache...

sudo systemctl restart httpd.service

推荐阅读