107

I'm trying to figure out what is the full complete configuration of an httpd setup.

All the configurations files are scattered in different files (/etc/httpd/conf.d, httpd.conf, various mod configs)

Is there a way to list the final httpd configuration?
Like the whole running setup configuration in a single file?

6

6 Answers 6

58

As noted by arco444, you can use apachectl -S to display an overview of the VirtualHosts currently running from the configs, and apachectl -M to display all currently loaded modules - I'm not aware of a tool to display the verbose output of all configs parsed (and which order they were parsed in) at launch of httpd, but I would recommend that you familiarise yourself with the general structure of the httpd config files:

Of particular note to your question: the 'main' apache config file is located in /etc/httpd/conf/httpd.conf (in the region of line 221 on a default httpd installation from the repos included in CentOS 6, which I assume you are using based on your post tags), and the 'supplementary' config files are located in /etc/httpd/conf.d and require to be included explicitly in the main config file. For example, if you search the httpd.conf file for the term 'Include', you will find the line Include conf.d/*.conf which is what includes all files of extension .conf in the subdirectory conf.d - in alphabetical order, so you will want to familiarise yourself with the importance of config file parsing at some point if possible.

As an aside, if you are using a shell based text editor such as vim, I suggest that you enable line numbering and syntax highlighting by default so that such lengthy config files are a bit easier to parse yourself and navigate - in the case of vim, you'd do so by creating a file in your home directory called .vimrc (or append to an existing one) and add the following lines:

set nu
syntax on
1
  • We are using apache 2.2 on CentOS. However, apachectl isn't available.
    – user674669
    May 1, 2020 at 11:33
40

As described in the Apache HTTP Server Documentation

If the config define -DDUMP_CONFIG is set, mod_info will dump the pre-parsed configuration to stdout during server startup.

httpd -DDUMP_CONFIG -k start

DUMP_CONFIG requires mod_infoenabled: a2enmod info!

In Ubuntu do the following

sudo apache2ctl -DDUMP_CONFIG

If you want to strip the line numbers do

sudo apache2ctl -DDUMP_CONFIG | grep -vE "^[ ]*#[ ]*[0-9]+:$"

or redirect to a file

sudo apache2ctl -DDUMP_CONFIG | grep -vE "^[ ]*#[ ]*[0-9]+:$" > /path/to/dump.conf

Known Limitations

mod_info provides its information by reading the parsed configuration, rather than reading the original configuration file. There are a few limitations as a result of the way the parsed configuration tree is created:

  • Directives which are executed immediately rather than being stored in the parsed configuration are not listed. These include ServerRoot, LoadModule, and LoadFile.
  • Directives which control the configuration file itself, such as Include, and are not listed, but the included configuration directives are.
  • Comments are not listed. (This may be considered a feature.)
  • Configuration directives from .htaccess files are not listed (since they do not form part of the permanent server configuration).
  • Container directives such as are listed normally, but mod_info cannot figure out the line number for the closing .
  • Directives generated by third party modules such as mod_perl might not be listed.
3
  • 2
    Great answer. For completeness sake: apache2ctl -DDUMP_CONFIG -t can be used for a dry run that doesn't require root permissions
    – TheMadsen
    Nov 11, 2021 at 7:53
  • On RHEL/AMI the equivalent command is sudo apachectl -DDUMP_CONFIG Aug 30, 2022 at 8:51
  • If mod_info is not enabled in your configuration (there are security concerns with configuring it properly), it can be loaded with the help of -C option and LoadModule directive. In my case I use: -t -C "LoadModule info_module modules/mod_info.so" -D DUMP_CONFIG Nov 20, 2023 at 22:54
17

Please use mod_info for that purpose: http://httpd.apache.org/docs/2.2/mod/mod_info.html

only down side is that if you need it to recover a deleted config and haven't already loaded the module it won't help you much

4

I have a script (alas, in Perl; forgive me, its old) that flattens the configuration files, removes comments (by default) and includes # FILE comments so you can figure out which file contains the thing you might be looking for.

I've written it with Apache httpd, although its also seen use with Oracle OHS

https://github.com/cameronkerrnz/scriptorium/blob/master/httpd-dump-config

Particularly useful for comparing configurations on different machines with SSH and diff/meld/etc.

Example:

httpd-dump-config | grep -i -e '# FILE:' -e servername -e serveralias
# FILE: /etc/httpd/conf/maintenance-curtain.conf
# FILE: /etc/httpd/conf.d/proxy.conf
# FILE: /etc/httpd/otago/secure-www.alias.conf
# FILE: /etc/httpd/conf.d/proxy.conf
    ServerName www.otago.ac.nz
    ServerAlias otago.ac.nz

Here's an example using diff (CLI) and meld (GUI):

diff -Bb <(httpd-dump-config) <(ssh root@revproxy2 httpd-dump-config)

meld <(httpd-dump-config) <(ssh root@revproxy2 httpd-dump-config) &

I've used this a lot over the years when navigating a config with thousands of lines of config spread over many files.

2
  • It does not support IncludeOptional directive. May 19, 2021 at 4:48
  • Or Macro and Use (but that could be considered a feature as well). -DDUMP_CONFIG, on the other hand, expands macros. Jan 30, 2023 at 23:37
0

When I had to maintain too many Apache configurations, I'd equipped myself with a script that did what you asked. It helped me a lot.

awk -v pc=$APCALL '

  NR == 1 {
    if (pf != "") {
      print "### End of "  pf  " ###"
    }
    print "### "  FILENAME  " ###"
    pf = FILENAME
  }
  { if (pc || ( $1 !~ "^#" && $0 != "" ) ) {
       printf "%5d %s\n", NR, $0
    }
  }
  $1 ~ /^Include(Optional)?$/ {
    $1 = ""
    system("for ACF in " $0 "; do apache_config.sh $ACF; done" )
  }
  END {
      print "### End of "  pf  " ###"
  }
' "$@"

You can set APCALL environment variable if you want to see the comments and empty lines, which I mostly didn't. Caveat: it has to be executed from ServerRoot.

0

There is main configuration folder in /etc directory.

cd /etc/httpd

there is multiple configuation folders.

[root@server httpd]# ls
conf  conf.d  conf.modules.d  logs  modules  run  state

to see detailed files user -R for recursive action.

[root@server httpd]# ls -R
.:
conf  conf.d  conf.modules.d  logs  modules  run  state
./conf:
httpd.conf  magic
./conf.d:
autoindex.conf  README  userdir.conf  welcome.conf
./conf.modules.d:
00-base.conf  00-brotli.conf  00-dav.conf  00-lua.conf  00-mpm.conf  00-optional.conf  00-proxy.conf  00-systemd.conf  01-cgi.conf  10-h2.conf  10-proxy_h2.conf  README
[root@server httpd]#

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.