有些时候,我们不能直观的看到相关软件配置文件的位置。最简单的办法,我们可以使用find命令直接查找文件,当然你需要提前知道配置文件的名称。当然我们还可以用一些比较巧妙的方式获的,简单高效速度快。

php配置文件的查找

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
//命令
php --ini

//结果输出  
Configuration File (php.ini) Path: /usr/local/etc/php7/etc
Loaded Configuration File:         /usr/local/etc/php7/etc/php.ini
Scan for additional .ini files in: /usr/local/etc/php7/etc/conf.d
Additional .ini files parsed:      /usr/local/etc/php7/etc/conf.d/pcntl.ini,
/usr/local/etc/php7/etc/conf.d/redis.ini,
/usr/local/etc/php7/etc/conf.d/swoole.ini
  • 主要配置文件: /usr/local/etc/php7/etc/php.ini
  • 用于查找额外配置文件的文件夹: /usr/local/etc/php7/etc/conf.d
  • 额外的配置文件:/usr/local/etc/php7/etc/conf.d/pcntl.ini 等

php-fpm、nginx配置文件路径的查找

php-fpm配置文件路径

1
2
3
4
//命令
php-fpm -t
//输出
[15-Dec-2017 11:39:58] NOTICE: configuration file /usr/local/bin/php7/etc/php-fpm.conf test is successful

可以看到配置文件位于/usr/local/bin/php7/etc/php-fpm.conf

nginx配置文件路径

1
2
3
4
5
//命令
nginx -t
//输出
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

strace命令的巧妙使用

1
2
3
4
5
6
7
8
//命令
strace -eopen /usr/local/bin/nginx 2>&1| grep conf
//输出
open("/usr/local/etc/nginx/conf/nginx.conf", O_RDONLY) = ...
open("/usr/local/etc/nginx/conf/mime.types", O_RDONLY) = ...
open("/etc/resolv.conf", O_RDONLY)      = ...
open("/etc/nsswitch.conf", O_RDONLY)    = ...
……

不仅能看到nginx加载常用的配置文件,还可以发现其加载了 nsswitch.conf 等不常见的配置文件

参考