When doing front-end operation and maintenance in a Linux system, sometimes you need to check the configuration of apache's error log, error log, access log, etc. These configurations are written in the httpd.conf file. How do you know which httpd.conf is currently used by apache? What? The steps are as follows.
Step 1. Find the apache startup command
[root@iZuf6crxor2b7uwzq9sutyZ ~]# ps -ef|grep httpd
root 4517 1 0 Nov19 ? 00:01:12 /usr/sbin/httpd -DFOREGROUND
root 8043 1 0 Jan13 ? 00:00:00 vim /etc/httpd/conf/httpd.conf
apache 19822 4517 0 10:40 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 19823 4517 0 10:40 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 19967 4517 0 10:43 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 20008 4517 0 10:45 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 20220 4517 0 10:53 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 20246 4517 0 10:54 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 20247 4517 0 10:54 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 20268 4517 0 10:55 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 20297 4517 0 10:56 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 20301 4517 0 10:56 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 20401 20345 0 10:58 pts/1 00:00:00 grep --color=auto httpd
If the result of the ps -ef|grep httpd command shows that the configuration file is specified with the -f option when apache is started, as shown in the following example, you can directly see the specific path of the configuration file as /home/apache/conf/httpd .conf.
/home/apache/bin/httpd -f /home/apache/conf/httpd.conf -k start
But the result of the first step does not show the -f option, then continue to the second step.
Step 2. Execute the httpd -S command to find out the configuration file path
Step 1 shows that the result of starting apache by the root user is the first one:
root 4517 1 0 Nov19 ? 00:01:12 /usr/sbin/httpd -DFOREGROUND
The path where the apache command is located is /usr/sbin/httpd. If you continue to execute the httpd -S command, you can see the specific configuration of apache.
[root@iZuf6crxor2b7uwzq9sutyZ ~]# /usr/sbin/httpd -S
[Fri Dec 04 11:13:12.738249 2020] [alias:warn] [pid 20927] AH00671: The Alias directive in /etc/httpd/conf/httpd.conf at line 145 will probably never match because it overlaps an earlier Alias.
VirtualHost configuration:
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/webapp"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
Mutex default: dir="/run/httpd/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex authdigest-opaque: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex authdigest-client: using_defaults
PidFile: "/run/httpd/httpd.pid"
Define: _RH_HAS_HTTPPROTOCOLOPTIONS
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=48
Group: name="apache" id=48
The result shows that the httpd.conf used by apache is /etc/httpd/conf/httpd.conf.