Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I view the complete httpd configuration?

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?

like image 710
Gnafu Avatar asked Nov 26 '14 15:11

Gnafu


People also ask

How do I get to httpd conf?

All the configuration files for Apache are located in /etc/httpd/conf and /etc/httpd/conf. d . The data for websites you'll run with Apache is located in /var/www by default, but you can change that if you want.

What is the configuration of httpd service?

The main configuration file is usually called httpd. conf . The location of this file is set at compile-time, but may be overridden with the -f command line flag. In addition, other configuration files may be added using the Include directive, and wildcards can be used to include many configuration files.

Which one is the configuration file for httpd?

The Apache HTTP Server configuration file is /etc/httpd/conf/httpd. conf. The httpd. conf file is well-commented and mostly self-explanatory.


2 Answers

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:

  • Apache 2.2 - General structure of the httpd config files
  • Apache 2.4 - 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 
like image 107
BE77Y Avatar answered Oct 12 '22 07:10

BE77Y


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.
like image 41
wolfrevo Avatar answered Oct 12 '22 07:10

wolfrevo