我已经使用以下步骤在Debian 7上安装了nginx
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nginx
sudo service nginx start
我已经确认通过从浏览器访问hostip来启动nginx。我如何找到nginx的版本?
nginx -v
因“&{39; command not found
错误
我验证了nginx存在于usr / sbin目录中,并且该目录被添加到$ PATH变量
答案 0 :(得分:59)
您的nginx似乎未正确安装。注意安装命令的输出:
sudo apt-get install nginx
要检查nginx版本,可以使用以下命令:
$ 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
了解更多信息: http://nginxlibrary.com/check-nginx-version/
您可以使用-v
参数仅显示Nginx版本,或使用-V
参数显示版本以及编译器版本和配置参数。
答案 1 :(得分:22)
答案 2 :(得分:9)
如果您不知道它在哪里,请先找到nginx。
ps -ef | grep nginx
然后你会看到这样的事情:
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
所以现在你已经知道nginx在哪里了。您可以使用-v或-V。类似的东西:
/opt/nginx/sbin/nginx -v
答案 3 :(得分:4)
我的猜测是,它不在你的道路上
在bash中,尝试:
echo $PATH
和
sudo which nginx
并查看包含nginx的文件夹是否也在$ PATH变量中
如果没有,请将文件夹添加到路径环境变量中,或者创建一个别名(并将其放在.bashrc中),或者我可以创建一个链接。
或sudo nginx -v
如果你只是想......
答案 4 :(得分:2)
确保您具有运行以下命令的权限。
如果您从终端检查nginx的手册页
man nginx
您可以找到它:
-V Print the nginx version, compiler version, and configure script parameters.
-v Print the nginx version.
然后输入终端
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
如果系统man nginx
命令中未安装nginx,则找不到手册页,因此请确保已安装nginx。
您还可以使用以下命令查找版本:
使用命令之一查找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
然后从终端运行:
/usr/sbin/nginx -v
nginx version: nginx/1.14.0
答案 5 :(得分:1)
尝试运行命令' whereis nginx '。它将为您提供正确的nginx安装路径,在我的情况下,nginx安装在'/ usr / local / sbin'中,因此我需要检查命令' echo $ PATH 的输出中是否存在此路径STRONG>”。如果在此命令的输出中找不到路径,则可以添加此命令。
假设我的' echo $ PATH '命令的输出是这样的:
~$ echo $PATH
/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/nginx/sbin
然后我可以通过以下命令在$ PATH中附加路径'/ usr / local / sbin':
~$ echo 'export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/nginx/sbin"' >> $HOME/.bashrc
请检查您的nginx安装路径可能与我的不同,但添加它们的步骤是相同的。