In this article I will tell you where Nginx server is installed and how to find out it’s configuration file after installation. It is very useful when you jump into an existing Nginx server and just want to find and modify it’s configuration files.
1. How To Find Nginx Install Path And Configuration Files.
There are several commands that you can use to find Nginx installation path and it’s configuration files path.
- Open a terminal and run
whereis nginx
command to return where the Nginx binary file is. But the Nginx bin directory path should exist in PATH system environment.$ whereis nginx nginx: /usr/bin/nginx /usr/local/nginx $ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
- If there are multiple Nginx binary file path records in above command result, you can run
which nginx
to show the currently used Nginx binary file path.$ which nginx /usr/bin/nginx
- You can run command
ls -al /usr/bin/nginx
to get the Nginx binary file linked real Nginx server binary file as below.$ ls -al /usr/bin/nginx lrwxrwxrwx. 1 root root 28 Dec 21 08:30 /usr/bin/nginx -> /www/server/nginx/sbin/nginx
- If the Nginx binary file path do not exist in environment variable PATH value, you can run
ps -ef | grep nginx
command to list currently running Nginx process information.$ ps -ef|grep nginx root 1412 1 0 Dec21 ? 00:00:00 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf
- From above
ps -ef|grep nginx
command, we can see Nginx binary file is located at/www/server/nginx/sbin/nginx
, and Nginx configuration file is located at/www/server/nginx/conf/nginx.conf
. - If the Nginx server is running now, you can also run command
nginx -t
to get and test the Nginx server configuration file.$ nginx -t nginx: the configuration file /www/server/nginx/conf/nginx.conf syntax is ok nginx: configuration file /www/server/nginx/conf/nginx.conf test is successful
2. Some Nginx Useful Commands.
- Command
nginx -V/v
can get current executing Nginx server version. The -V will return more detail version information.$ nginx -V nginx version: nginx/1.18.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) built with OpenSSL 1.1.1i 8 Dec 2020 .............. $ nginx -v nginx version: nginx/1.18.0
- Start / stop / restart / reload Nginx server.
$ sudo systemctl start nginx $ sudo systemctl stop nginx $ sudo systemctl restart nginx $ sudo systemctl reload nginx
- Get Nginx running status.
$ sudo systemctl status nginx
- Enable / Disable launch Nginx server when Linux server is started.
$ sudo systemctl enable nginx $ sudo systemctl disable nginx
- Display Nginx command line help information.
$ sudo systemctl -h nginx systemctl [OPTIONS...] {COMMAND} ... Query or send control commands to the systemd manager. -h --help Show this help --version Show package version --system Connect to system manager -H --host=[USER@]HOST Operate on remote host -M --machine=CONTAINER Operate on local container -t --type=TYPE List units of a particular type --state=STATE List units with particular LOAD or SUB or ACTIVE state ......... .........