添加 VirtualHost conf 文件后 apache 不会重新启动,为什么?

添加 VirtualHost conf 文件后 apache 不会重新启动,为什么?

在服务器中,当我在底部添加包含文件后CentOS 7键入时,出现以下错误:sudo apachectl restarthttpd.conf

Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details.

当我输入 时sudo systemctl status httpd.service -l,结果是:

httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
   Active: failed (Result: exit-code) since Tue 2014-12-23 20:10:37 EST; 2min 15s ago
  Process: 2101 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
  Process: 2099 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 2099 (code=exited, status=1/FAILURE)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"

Dec 23 20:10:37 ip-address httpd[2099]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::e23f:49ff:feb7:2a21. Set the 'ServerName' directive globally to suppress this message
Dec 23 20:10:37 ip-address systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Dec 23 20:10:37 ip-address systemd[1]: Failed to start The Apache HTTP Server.
Dec 23 20:10:37 ip-address systemd[1]: Unit httpd.service entered failed state.

apache如果注释掉 include 指令, 我可以重新启动,并且可以通过取消注释 include 指令来再次重新创建错误。如何才能apache正确开始使用包含文件的内容?

httpd.conf触发错误的底部行是: IncludeOptional sites-enabled/*.conf.conf该文件夹中唯一的文件sites-enabledmydomain.com.conf,其中包含以下内容:

<VirtualHost *:80>
    ServerName www.mydomain.com
    ServerAlias mydomain.com
    DocumentRoot /var/www/mydomain.com/public_html
    ErrorLog /var/www/mydomain.com/error.log
    CustomLog /var/www/mydomain.com/requests.log combined
</VirtualHost>

除了上面的一行 include 指令之外,它httpd.conf与预安装的相同。httpd我知道,因为我在触发此错误之前就这样sudo yum remove httpd mod_ssl做了。可以在文件共享网站上阅读sudo yum install httpd mod_ssl全文httpd.conf点击此链接

我在明确遵循时遇到了这个问题本教程中的步骤

当我注释掉包含文件时,http/mydomain.com成功提供了位于 中的静态内容/var/www/html,这是DocumentRoot在 中定义的httpd.conf。问题似乎来自VirtualHost上面显示的包含文件中的指令。 为了帮助诊断,我在下面的 EDIT#3 中包含了指向.conf三个包含指令中包含的所有文件的链接httpd.conf

编辑#1

当我尝试 m32 的建议更改/etc/hostname为 Define时mydomain.comapache仍然不会重新启动,结果systemctl status httpd.service如下:

[sudo_user_account@server-ip-address ~]$ sudo systemctl status httpd.service -l
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
   Active: failed (Result: exit-code) since Tue 2014-12-23 14:25:35 EST; 20s ago
  Process: 31993 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
  Process: 31991 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 31991 (code=exited, status=1/FAILURE)
   Status: "Total requests: 1; Current requests/sec: 0; Current traffic:   0 B/sec"

Dec 23 14:25:35 hostname systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Dec 23 14:25:35 hostname systemd[1]: Failed to start The Apache HTTP Server.
Dec 23 14:25:35 hostname systemd[1]: Unit httpd.service entered failed state.  

编辑#2

我还尝试了 eyoung100 的建议来更改文件的内容/etc/hosts,如下图所示,但我仍然遇到上面 EDIT#1 中定义的相同错误。

编辑#3

根据 DerekC 的要求,我运行sudo apachectl configtest并得到:

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::e23f:49ff:feb7:2a21. Set the 'ServerName' directive globally to suppress this message
Syntax OK

此外,根据 GarethTheRed 的建议,我检查了包含指令httpd.conf。共有三个 include 指令httpd.conf。我在下面列出了这三个文件,以及每个指令文件夹中的所有文件。这些都是.confhttpd.我还没有修改其中任何一个。您可以.conf通过单击以下链接在文件共享站点上 查看每个文件:

Include conf.modules.d/*.conf引用目录中的以下文件conf.modules.d00-base.conf
00-dav.conf
00-lua.conf
00-mpm.conf
00-proxy.conf
00-ssl.conf
00-systemd.conf
01-cgi.conf

IncludeOptional conf.d/*.conf引用目录中的以下文件conf.d自动索引文件
SSL配置文件
用户目录配置文件
欢迎.conf
还有一个 README 文件,我在这里省略了。

此外,IncludeOptional sites-enabled/*.conf上述 OP 中详细概述了该指令及其内容。

这些包含文件是否与VirtualHost中的设置冲突mydomain.com.conf

编辑#4

根据 garethTheRed 的建议,我移动mydomain.com.conf到该目录,然后开始一一conf.d注释行,直到能够重新启动。然后我开始取消注释行,看看还有多少行可以保留并且仍然可以重新启动。我能够重新启动,但继续产生相同的警告: mydomain.com.confhttpdhttpdhttpdsystemctl status httpd.service -l

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::e23f:49ff:feb7:2a21. Set the 'ServerName' directive globally to suppress this message

VirtualHost允许启动(尽管继续生成上述警告)的语法如下httpd

<VirtualHost *:80>
    ServerName www.mydomain.com
    ServerAlias mydomain.com
    DocumentRoot /var/www/mydomain.com/public_html
</VirtualHost>  

请注意,我必须省略以下几行,它们的存在将警告升级为完全无法启动 http:

# ErrorLog /var/www/mydomain.com/error.log
# CustomLog /var/www/mydomain.com/requests.log combined

另外,我跑了sudo journalctl -xelu httpd,终端通过多次重复以下内容进行回复:

-- 
-- Unit httpd.service has finished shutting down.
Dec 24 17:48:43 server-ip-address systemd[1]: Stopped The Apache HTTP Server.
-- Subject: Unit httpd.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit httpd.service has finished shutting down.
Dec 24 17:48:48 server-ip-address systemd[1]: Starting The Apache HTTP Server...
-- Subject: Unit httpd.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit httpd.service has begun starting up.
Dec 24 17:48:48 server-ip-address httpd[10364]: AH00558: httpd: Could not reliably d
Dec 24 17:48:48 server-ip-address systemd[1]: Started The Apache HTTP Server.
-- Subject: Unit httpd.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit httpd.service has finished starting up.
-- 
-- The start-up result is done.
lines 887-909/909 (END)

注意:无论我使用eyoung100的hosts文件还是m32的host文件,上述结果都保持不变。 为了回答这个问题,我认为我应该能够创建日志文件并避免服务器名称警告。 否则,我担心后续配置 httpd 的步骤很容易出现挥之不去的错误。

答案1

日志导致错误,因为apache无法写入您网站的根目录。即使你要修复文件权限,你仍然会被 SELinux 阻止;它只允许apache将日志写入/var/log/httpd.最简单的解决方案是更改您的网站以登录到此目录 - 也许使用包含网站名称的文件名,以便将其与其他日志区分开来。

ErrorLog /var/log/httpd/mydomain_com_error.log
CustomLog /var/log/httpd/mydomain_com_requests.log combined

要设置服务器的主机名并消除 AH00558 警告,只需使用:

hostnamectl set-hostname --static <FQDN of your machine>

例如

hostnamectl set-hostname --static mydomain.com

答案2

当我忘记设置机器的主机名时,出现此错误。你这样做了吗?
运行这个命令:

echo 'example.com' >> /etc/hostname  

验证与hostname

编辑:
使用更新的 OP,看起来您的主机文件设置不正确。这是我的样子;

127.0.0.1 localhost.localdomain localhost
# Auto-generated hostname. Please do not remove this comment.
166.66.666.66 m32.me m32
::1     ip6-localhost ip6-loopback

尝试将其设置为类似的简单内容。当然,将所有信息替换为您自己的信息。
166.66.666.66使用您自己的 IP
m32.me and m32和您的域,以及不带 TLD 的域

相关内容