How To Find Where Nginx Is Installed And Locate The Nginx.conf File Which Nginx Is Actually Using

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.

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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.
  6. 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.

  1. 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
  2. Start / stop / restart / reload Nginx server.
    $ sudo systemctl start nginx
    $ sudo systemctl stop nginx
    $ sudo systemctl restart nginx
    $ sudo systemctl reload nginx
  3. Get Nginx running status.
    $ sudo systemctl status nginx
  4. Enable / Disable launch Nginx server when Linux server is started.
    $ sudo systemctl enable nginx
    $ sudo systemctl disable nginx
  5. 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

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.