Find nginx version?

NginxVersionCommand Line-Interface

Nginx Problem Overview


I have installed nginx on Debian 7 with the following steps

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nginx
sudo service nginx start

I have confirmed that this starts nginx by accessing the hostip from the browser. How do I find out the version of nginx?

nginx -v fails with the 'command not found error

I verified that nginx exists in the usr/sbin directory and that directory is added to the $PATH variable

Nginx Solutions


Solution 1 - Nginx

It seems that your nginx hasn't been installed correctly. Pay attention to the output of the installation commands:

sudo apt-get install nginx

To check the nginx version, you can use this command:

$ nginx -v
nginx version: nginx/0.8.54

$ nginx -V
nginx version: nginx/0.8.54
TLS SNI support enabled
configure arguments: --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-debug --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/build/buildd/nginx-0.8.54/debian/modules/nginx-upstream-fair

For more information: http://nginxlibrary.com/check-nginx-version/

You can use -v parameter to display the Nginx version only, or use the -V parameter to display the version, along with the compiler version and configuration parameters.

Solution 2 - Nginx

In my case, I try to add sudo

sudo nginx -v

enter image description here

Solution 3 - Nginx

If you don't know where it is, locate nginx first.

ps -ef | grep nginx

Then you will see something like this:

root      4801     1  0 May23 ?        00:00:00 nginx: master process /opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
root     12427 11747  0 03:53 pts/1    00:00:00 grep --color=auto nginx
nginx    24012  4801  0 02:30 ?        00:00:00 nginx: worker process                              
nginx    24013  4801  0 02:30 ?        00:00:00 nginx: worker process

So now you already know where nginx is. You can use the -v or -V. Something like:

/opt/nginx/sbin/nginx -v

Solution 4 - Nginx

My guess is it's not in your path.
in bash, try:
echo $PATH
and
sudo which nginx
And see if the folder containing nginx is also in your $PATH variable.
If not, either add the folder to your path environment variable, or create an alias (and put it in your .bashrc) ooor your could create a link i guess.
or sudo nginx -v if you just want that...

Solution 5 - Nginx

Make sure that you have permissions to run the following commands.

If you check the man page of nginx from a terminal

man nginx

you can find this:

-V             Print the nginx version, compiler version, and configure script parameters.

-v             Print the nginx version.

Then type in terminal

nginx -v
nginx version: nginx/1.14.0

nginx -V
nginx version: nginx/1.14.0
built with OpenSSL 1.1.0g  2 Nov 2017
TLS SNI support enabled

If nginx is not installed in your system man nginx command can not find man page, so make sure you have installed nginx.

You can also find the version using this command:

Use one of the command to find the path of nginx

ps aux | grep nginx
ps -ef | grep nginx

root       883  0.0  0.3  44524  3388 ?        Ss   Dec07   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on

Then run from terminal:

/usr/sbin/nginx -v

nginx version: nginx/1.14.0

Solution 6 - Nginx

Try running command whereis nginx. It will give you the correct path of the nginx installation, in my case nginx is installed in /usr/local/sbin, so I need to check if this path exists in output of command echo $PATH. If you don't find the path in the output of this command, then you can add this.

Suppose the output of my echo $PATH command is this:

~$ echo $PATH
/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/nginx/sbin

Then I can append the path /usr/local/sbin in $PATH by following command:

~$ echo 'export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/nginx/sbin"' >> $HOME/.bashrc

Please check your nginx installation path may differ from mine, but the steps for adding them are same.

Solution 7 - Nginx

search if iginx is installed or any package in your system

which nginx

OR

sudo which nginx

if previously nginx installed result will be like this /sbin/nginx /bin/nginx

if you use rhel, it will show you all installed modules

yum search nginx

OR check nginx version in rhel

rpm -q nginx

Result look like this

> nginx-1.14.1-9.module+el8.0.0+4108+af250afe.x86_64

OR

sudo nginx -v

Result look like

> nginx version: nginx/1.14.1

don't use "nginx --version" it will show unexpected errors. I'm a RHEL user.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser_mdaView Question on Stackoverflow
Solution 1 - Nginxhassan ketabiView Answer on Stackoverflow
Solution 2 - NginxFrank NguyenView Answer on Stackoverflow
Solution 3 - Nginxtungsten_carbideView Answer on Stackoverflow
Solution 4 - NginxxorView Answer on Stackoverflow
Solution 5 - NginxbhordupurView Answer on Stackoverflow
Solution 6 - NginxHarsh MathurView Answer on Stackoverflow
Solution 7 - NginxRonny DsouzaView Answer on Stackoverflow