1. Search through which command
$ which nginx /usr/sbin/nginx
The which command will search for the nginx executable file in the system environment variable PATH and return the path. Therefore, the installation location of nginx in the system can be easily found through the which command.
2. Search through whereis command
$ whereis nginx nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx /usr/share/man/man1/nginx.1.gz
The whereis command will search for nginx in the default library file directory, binary file directory, specified directory, etc., and return all related files and path information. Among them, "/usr/sbin/nginx" is the absolute path of the nginx executable file, "/etc/nginx" is the configuration file directory of nginx, "/usr/share/nginx" is the html file directory of nginx, and nginx's man manual path.
3. Search through the find command
$ sudo find / -name nginx /etc/nginx /usr/sbin/nginx /var/log/nginx /var/lib/nginx
The find command will traverse all files and subdirectories under the specified path and find files or directories that meet the conditions according to the specified rules. The above command will search for all files or directories named nginx in the root directory of the system and return the search results. As you can see, the returned results include paths such as /etc/nginx, /usr/sbin/nginx, /var/log/nginx, and /var/lib/nginx.
4. Search through ps command
$ ps aux | grep nginx root 798 0.0 0.5 25616 5752 ? Ss 10月04 0:03 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; nginx 799 0.0 0.6 26396 6496 ? S 10月04 0:09 nginx: worker process nginx 800 0.0 0.6 26396 6496 ? S 10月04 0:09 nginx: worker process nginx 801 0.0 0.6 26396 6496 ? S 10月04 0:09 nginx: worker process nginx 802 0.0 0.6 26396 6496 ? S 10月04 0:09 nginx: worker process
The ps command will list the system's process information. Use the grep command to filter out the nginx process and view its command line parameters. You can get the installation path and other parameter details of nginx.
5. Search through rpm command
$ rpm -ql nginx /etc/nginx /etc/nginx/uwsgi_params /etc/nginx/mime.types /etc/nginx/fastcgi_params /etc/nginx/sites-available /etc/nginx/sites-available/default /etc/nginx/scgi_params /etc/nginx/geoip.conf /etc/nginx/nginx.conf /etc/nginx/uwsgi_params.default /etc/nginx/conf.d /etc/nginx/conf.d/default.conf /usr/share/doc/nginx /usr/share/doc/nginx/CHANGES.RU.gz /usr/share/doc/nginx/LICENSE /usr/share/doc/nginx/README /usr/share/man/man1/nginx.1.gz /usr/lib/systemd/system/nginx.service /usr/sbin/nginx
If Nginx was installed by compiling from source, the above method may not work. At this time, you can use the rpm command to find the Nginx installation path. rpm is a package management tool for Red Hat-based Linux distributions that can list and query installed software packages and their details.
6. Search through dpkg command
$ dpkg -L nginx /etc /etc/nginx /etc/nginx/uwsgi_params /etc/nginx/mime.types /etc/nginx/fastcgi_params /etc/nginx/sites-available /etc/nginx/sites-available/default /etc/nginx/scgi_params /etc/nginx/geoip.conf /etc/nginx/nginx.conf /etc/nginx/uwsgi_params.default /etc/init.d /etc/init.d/nginx /etc/default /etc/default/nginx /etc/logrotate.d /etc/logrotate.d/nginx /usr/share /usr/share/doc /usr/share/doc/nginx /usr/share/doc/nginx/CHANGES.RU.gz /usr/share/doc/nginx/LICENSE /usr/share/doc/nginx/README.Debian /usr/share/man /usr/share/man/man1 /usr/share/man/man1/nginx.1.gz /usr/sbin /usr/sbin/nginx /usr/share/lintian /usr/share/lintian/overrides /usr/share/lintian/overrides/nginx /usr/lib /usr/lib/tmpfiles.d /usr/lib/tmpfiles.d/nginx.conf
If Nginx was installed through Debian or Ubuntu's package manager apt-get, you can use the dpkg command to find the installation path of Nginx. dpkg is Debian's package management tool. You can also view and obtain software package information packaged in dpkg format.
Summarize:
You can find the installation path of Nginx in Linux through commands such as which, whereis, find, ps, rpm and dpkg. The specific methods vary depending on the installation method and system environment, and you need to choose different methods according to the specific circumstances.