Cod*_*Med 14 dns centos systemd apache-httpd
在CentOS 7服务器中,sudo apachectl restart在底部添加包含文件后键入时出现以下错误httpd.conf:
Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details.
Run Code Online (Sandbox Code Playgroud)
当我输入时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.
Run Code Online (Sandbox Code Playgroud)
我可以apache,如果我注释掉include指令重新启动,我可以通过取消注释include指令再次重现错误。 如何apache正确使用包含文件的内容?
底部httpd.conf触发错误的行是:IncludeOptional sites-enabled/*.conf。.conf文件sites-enabled夹中唯一的文件是mydomain.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>
Run Code Online (Sandbox Code Playgroud)
该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/hostnameto define 时mydomain.com,apache仍然不会重新启动,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.
Run Code Online (Sandbox Code Playgroud)
编辑#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
Run Code Online (Sandbox Code Playgroud)
此外,根据 GarethTheRed 的建议,我检查了httpd.conf 中的 include 指令。httpd.conf 中有三个包含指令。我在下面列出了三个,以及位于每个指令文件夹中的所有文件。这些是.conf安装的所有标准文件httpd。我还没有修改它们中的任何一个。您可以.conf通过单击以下链接在文件共享站点查看每个文件:
Include conf.modules.d/*.conf引用conf.modules.d目录中的以下文件:
00-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目录:
autoindex.conf
的ssl.conf
userdir.conf
welcome.conf
还有一个README文件,我在这里省略。
此外,该IncludeOptional sites-enabled/*.conf指令及其内容在上面的 OP 中进行了全面概述。
这些包含文件中的任何一个是否与 中的VirtualHost设置冲突mydomain.com.conf?
编辑#4
根据 garethTheRed 的建议,我移至mydomain.com.conf该conf.d目录,然后开始逐行注释掉行,mydomain.com.conf直到httpd能够重新启动。然后我开始取消注释行以查看可以保留多少行并且httpd仍然重新启动。我能够httpd重新启动,但systemctl 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
Run Code Online (Sandbox Code Playgroud)
VirtualHost允许httpd启动(虽然继续生成上述警告)的语法如下:
<VirtualHost *:80>
ServerName www.mydomain.com
ServerAlias mydomain.com
DocumentRoot /var/www/mydomain.com/public_html
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
请注意,我必须省略以下几行,它们的存在会将警告升级为完全无法启动 http:
# ErrorLog /var/www/mydomain.com/error.log
# CustomLog /var/www/mydomain.com/requests.log combined
Run Code Online (Sandbox Code Playgroud)
另外,我跑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)
Run Code Online (Sandbox Code Playgroud)
注意:无论我使用eyoung100的hosts文件还是m32的host文件,上面的结果都是一样的。 为了回答这个问题,我想我应该能够创建日志文件并避免服务器名称警告。 否则,我担心后续配置httpd的步骤容易出现挥之不去的错误。
gar*_*Red 19
日志导致错误,因为apache无法写入您网站的根目录。即使你修复了文件权限,你仍然会被 SELinux 阻止;只允许apache将日志写入/var/log/httpd. 最简单的解决方案是更改您的网站以登录到此目录 - 可能使用包含网站名称的文件名,以便将其与其他日志区分开来。
ErrorLog /var/log/httpd/mydomain_com_error.log
CustomLog /var/log/httpd/mydomain_com_requests.log combined
Run Code Online (Sandbox Code Playgroud)
要设置服务器的主机名并摆脱 AH00558 警告,只需使用:
hostnamectl set-hostname --static <FQDN of your machine>
Run Code Online (Sandbox Code Playgroud)
例如
hostnamectl set-hostname --static mydomain.com
Run Code Online (Sandbox Code Playgroud)