添加VirtualHost conf文件後apache不會重新啟動,為什麼不呢?
在伺服器中,在底部添加包含文件後
CentOS 7
鍵入時出現以下錯誤:sudo apachectl restart``httpd.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
如果我註釋掉包含指令,我可以重新啟動,並且我可以通過取消註釋包含指令來重新創建錯誤 。如何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>
除了上面的一行包含指令外,它
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
為 definemydomain.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.
編輯#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中的包含指令。httpd.conf中有三個包含指令。我列出了下面三個,以及位於每個指令文件夾中的所有文件。這些都是
.conf
隨httpd
. 我還沒有修改任何一個。您可以.conf
通過點擊以下連結在文件共享站點查看每個文件:
Include conf.modules.d/*.conf
引用目錄中的以下文件conf.modules.d
: 00-base.conf
IncludeOptional conf.d/*.conf
引用目錄中的以下文件conf.d
: autoindex.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
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文件,上面的結果都是一樣的。 為了回答這個問題,我想我應該能夠創建日誌文件並避免 servername 警告。 否則,我擔心配置httpd的後續步驟會容易出現揮之不去的錯誤。
日誌導致錯誤,因為
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