运行Apache的configtest时确定有问题的文件

运行https configtest时有没有办法确定有问题的文件?

例如,而不是:

 Warning: DocumentRoot [/var/www/whatever.com/webroot] does not exist Warning: DocumentRoot [/var/www/example.com/webroot] does not exist 

我能看见:

 Warning: DocumentRoot [/var/www/whatever.com/webroot] does not exist in /etc/httpd/conf.d/file.conf Warning: DocumentRoot [/var/www/example.com/webroot] does not exist in /etc/httpd/conf.d/other_file.conf 

我审查了帮助/ man并search,但找不到选项或等效的命令。

不幸的是,apachectl不提供这个信息。

您最好的解决scheme是简单地使用grep来searchconfiguration文件,查找错误信息中显示的string。

只是添加一些额外的信息, apachectl脚本本身并没有太多的工作,只是用一个标志调用httpd二进制文件:

  configtest) $HTTPD -t ERROR=$? ;; 

所以这个问题必须在核心中加以解决。

这在apache-2.4是固定的:

 # systemctl status httpd httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled) Active: failed (Result: exit-code) since Fri 2014-06-20 20:36:01 CEST; 1s ago Process: 3331 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS) Process: 3329 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE) Main PID: 3329 (code=exited, status=1/FAILURE) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" Jun 20 20:36:01 foo.com httpd[3329]: AH00526: Syntax error on line 15 of /etc/httpd/conf.d/012-some-vhost.conf: Jun 20 20:36:01 foo.com httpd[3329]: Invalid command 'UseCanonicalNamex', perhaps misspelled or defined by a module not included in the server configuration Jun 20 20:36:01 foo.com systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE Jun 20 20:36:01 foo.com systemd[1]: Failed to start The Apache HTTP Server. Jun 20 20:36:01 foo.com systemd[1]: Unit httpd.service entered failed state. 

相关的代码在server/config.c