2

try to prompt this command nginx -V but shell returns fish: Unknown command “nginx”

If I try sudo service nginx status I could see Usage: /etc/init.d/nginx {start|stop|restart|reload|force-reload}

Why nginx -V is not work?

getElementById
  • 23
  • 1
  • 1
  • 5

2 Answers2

6

/etc/init.d/nginx is a shell script to start/stop/... the nginx service

$ file /etc/init.d/nginx
/etc/init.d/nginx: POSIX shell script, ASCII text executable

nginx binary is different and usually present in /usr/sbin/. Add that directory to your PATH.

$ file /usr/sbin/nginx
/usr/sbin/nginx: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=c14e988f9696733869b790f49e27a488b0aff4c2, stripped

Or view the file /etc/init.d/nginx to find out where nginx is installed.

helloV
  • 50,176
  • 7
  • 137
  • 145
  • I found out that nginx was installed to `/opt/nginx/` How can I make add that directory to PATH? – getElementById Mar 20 '16 at 06:55
  • Depends on what `shell` you are using. `export PATH=/opt/nginx:$PATH` should work. – helloV Mar 20 '16 at 07:01
  • I have used `set -U fish_user_paths /opt/nginx $fish_user_paths` but if I am entering command `nginx -V` shell still saying `fish: Unknown command “nginx”` ` – getElementById Mar 20 '16 at 07:21
  • You don't need to add the `/usr/sbin` directory to the `PATH` variable. You can access the contents of the directory `/usr/sbin` globally using the command `sudo`, `sbin` is short for **secure binary**. Example for execute `nginx` globally: `sudo nginx` – Laode Muhammad Al Fatih Nov 22 '19 at 01:05
  • Under an old `nginx/1.14.0` version the binary was found under `/opt/nginx/sbin/nginx` on an `Ubuntu 16.04 Xenial` server. – joseluisq Aug 26 '20 at 07:20
0

I had a somewhat similar issues while running nginx -s reload in a linux alpine docker container. I ran cat /etc/init.d/nginx and noticed that the scripts are using a bang openrc binary. installed openrc and voila the command works.

alpine linux cmd (not sure what ubuntu command is)

apk add openrc
derpdewp
  • 182
  • 7