[ubuntu] How to verify if nginx is running or not?

After 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

Following jsinh's blog, I installed it using:

sudo apt-get update
sudo apt-get install nginx -y

I was trying to understand whether it is working or not by using:

ifconfig eth0 | grep inet | awk '{ print $2}'

After running

sudo service nginx start
sudo service nginx stop

However, the output is always the same:

Nginx status

How to verify if nginx is running or not?

This question is related to ubuntu nginx mono

The answer is


This is probably system-dependent, but this is the simplest way I've found.

if [ -e /var/run/nginx.pid ]; then echo "nginx is running"; fi

That's the best solution for scripting.


For Mac users

I found out one more way: You can check if /usr/local/var/run/nginx.pid exists. If it is - nginx is running. Useful way for scripting.

Example:

if [ -f /usr/local/var/run/nginx.pid ]; then
   echo "Nginx is running"

fi

You could use lsof to see what application is listening on port 80:

sudo lsof -i TCP:80

The other way to see it in windows command line :

tasklist /fi "imagename eq nginx.exe"

INFO: No tasks are running which match the specified criteria.

if there is a running nginx you will see them


If you are on mac machine and had installed nginx using

brew install nginx

then

brew services list

is the command for you. This will return a list of services installed via brew and their corresponding status.

enter image description here


None of the above answers worked for me so let me share my experience. I am running nginx in a docker container that has a port mapping (hostPort:containerPort) - 80:80 The above answers are giving me strange console output. Only the good old 'nmap' is working flawlessly even catching the nginx version. The command working for me is:

 nmap -sV localhost -p 80

We are doing nmap using the -ServiceVersion switch on the localhost and port: 80. It works great for me.


Can also use the following code to check the nginx status:

   sudo /etc/init.d/nginx status

Not sure which guide you are following, but if you check out this page,

https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-14-04-lts

It uses another command

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//' 

and also indicates what result is expected.


The modern (systemctl) way of doing it:

systemctl is-active nginx

You can use the exit value in your shell scripts as follows:

systemctl -q is-active nginx && echo "It is active, do something"

Examples related to ubuntu

grep's at sign caught as whitespace "E: Unable to locate package python-pip" on Ubuntu 18.04 How to Install pip for python 3.7 on Ubuntu 18? "Repository does not have a release file" error ping: google.com: Temporary failure in name resolution How to install JDK 11 under Ubuntu? How to upgrade Python version to 3.7? Issue in installing php7.2-mcrypt Install Qt on Ubuntu Failed to start mongod.service: Unit mongod.service not found

Examples related to nginx

Kubernetes service external ip pending nginx: [emerg] "server" directive is not allowed here Disable nginx cache for JavaScript files Nginx upstream prematurely closed connection while reading response header from upstream, for large requests Nginx: Job for nginx.service failed because the control process exited How can I have same rule for two locations in NGINX config? How to verify if nginx is running or not? Find nginx version? Docker Networking - nginx: [emerg] host not found in upstream How do I rewrite URLs in a proxy response in NGINX

Examples related to mono

.NET Core vs Mono How to verify if nginx is running or not? How to serialize/deserialize to `Dictionary<int, string>` from custom XML not using XElement? Develop Android app using C# How to include the reference of DocumentFormat.OpenXml.dll on Mono2.10? Process.start: how to get the output? Most useful NLog configurations Running ASP.Net on a Linux based server Will Google Android ever support .NET? Encrypt and decrypt a string in C#?