如何验证 nginx 是否为 运行?
How to verify if nginx is running or not?
running an ASP.NET vNext project on my local machine I was trying to figure out how I can run it on nginx as it looks to be a recommended choice
之后
sudo apt-get update
sudo apt-get install nginx -y
我试图通过以下方式了解它是否有效:
ifconfig eth0 | grep inet | awk '{ print }'
运行
之后
sudo service nginx start
sudo service nginx stop
但是,输出总是一样的:
How to verify if nginx is running or not?
不确定您在遵循哪个指南,但是如果您查看此页面,
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-14-04-lts
它使用了另一个命令
ip addr show eth0 | grep inet | awk '{ print ; }' | sed 's/\/.*$//'
并指出预期的结果。
您可以使用 lsof
来查看正在侦听端口 80 的应用程序:
sudo lsof -i TCP:80
根据您的要求,以下命令应 help:
service nginx status
None 以上答案对我有用所以让我分享我的经验。我是 运行 nginx 在一个 docker 有端口映射的容器中 (hostPort:containerPort) - 80:80
上面的答案给我奇怪的控制台输出。只有老好人 'nmap' 可以完美地工作,甚至可以捕获 nginx 版本。对我有用的命令是:
nmap -sV localhost -p 80
我们正在使用本地主机和端口 80 上的 -ServiceVersion 开关执行 nmap。它对我来说非常有用。
这可能与系统有关,但这是我找到的最简单的方法。
if [ -e /var/run/nginx.pid ]; then echo "nginx is running"; fi
这是编写脚本的最佳解决方案。
也可以使用如下代码查看nginx状态:
sudo /etc/init.d/nginx status
现代(systemctl
)的做法:
systemctl is-active nginx
您可以在 shell 脚本中使用退出值,如下所示:
systemctl -q is-active nginx && echo "It is active, do something"
如果您在 mac machine 上并且使用
安装了 nginx
brew install nginx
然后
brew services list
是给你的命令。这将 return 通过 brew 安装的服务及其相应状态的列表。
在 windows 命令行中查看它的另一种方式:
tasklist /fi "imagename eq nginx.exe"
INFO: No tasks are running which match the specified criteria.
如果有 运行 nginx 你会看到它们
Mac 用户
我发现了另一种方法:您可以检查 /usr/local/var/run/nginx.pid
是否存在。如果是 - nginx 是 运行。编写脚本的有用方法。
示例:
if [ -f /usr/local/var/run/nginx.pid ]; then
echo "Nginx is running"
fi
service nginx status
将在非基于 systemd 的版本上工作。
在基于 systemd 的版本上,例如 Ubuntu Linux 16.04 LTS 及更高版本,请使用以下命令;
systemctl status nginx
running an ASP.NET vNext project on my local machine I was trying to figure out how I can run it on nginx as it looks to be a recommended choice
之后sudo apt-get update
sudo apt-get install nginx -y
我试图通过以下方式了解它是否有效:
ifconfig eth0 | grep inet | awk '{ print }'
运行
之后sudo service nginx start
sudo service nginx stop
但是,输出总是一样的:
How to verify if nginx is running or not?
不确定您在遵循哪个指南,但是如果您查看此页面,
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-14-04-lts
它使用了另一个命令
ip addr show eth0 | grep inet | awk '{ print ; }' | sed 's/\/.*$//'
并指出预期的结果。
您可以使用 lsof
来查看正在侦听端口 80 的应用程序:
sudo lsof -i TCP:80
根据您的要求,以下命令应 help:
service nginx status
None 以上答案对我有用所以让我分享我的经验。我是 运行 nginx 在一个 docker 有端口映射的容器中 (hostPort:containerPort) - 80:80 上面的答案给我奇怪的控制台输出。只有老好人 'nmap' 可以完美地工作,甚至可以捕获 nginx 版本。对我有用的命令是:
nmap -sV localhost -p 80
我们正在使用本地主机和端口 80 上的 -ServiceVersion 开关执行 nmap。它对我来说非常有用。
这可能与系统有关,但这是我找到的最简单的方法。
if [ -e /var/run/nginx.pid ]; then echo "nginx is running"; fi
这是编写脚本的最佳解决方案。
也可以使用如下代码查看nginx状态:
sudo /etc/init.d/nginx status
现代(systemctl
)的做法:
systemctl is-active nginx
您可以在 shell 脚本中使用退出值,如下所示:
systemctl -q is-active nginx && echo "It is active, do something"
如果您在 mac machine 上并且使用
安装了 nginxbrew install nginx
然后
brew services list
是给你的命令。这将 return 通过 brew 安装的服务及其相应状态的列表。
在 windows 命令行中查看它的另一种方式:
tasklist /fi "imagename eq nginx.exe"
INFO: No tasks are running which match the specified criteria.
如果有 运行 nginx 你会看到它们
Mac 用户
我发现了另一种方法:您可以检查 /usr/local/var/run/nginx.pid
是否存在。如果是 - nginx 是 运行。编写脚本的有用方法。
示例:
if [ -f /usr/local/var/run/nginx.pid ]; then
echo "Nginx is running"
fi
service nginx status
将在非基于 systemd 的版本上工作。
在基于 systemd 的版本上,例如 Ubuntu Linux 16.04 LTS 及更高版本,请使用以下命令;
systemctl status nginx