添加新的虚拟主机时,Apache服务器无法启动

时间:2019-01-16 18:47:30

标签: apache centos7 virtual hosts

我目前在Linode上有一个运行Apache2的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.

1 个答案:

答案 0 :(得分:1)

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

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