How can I check if current web server is NGINX or Apache using bash script?

check if nginx is running
check httpd status centos 7
check nginx status linux
check if nginx is running bash
how to test apache web server
how to monitor apache web server in linux
how to check if server is apache
how to check http server is running in linux

I have a Laravel project deployed on Ubuntu VM. I have a script that I am working on right now that to know if the current VM deployed using nginx or Apache programmatically.

I know I can just check using these ps and grep command I will find that out

root@theawsbiz:~# ps -aux | grep apache                                                                                                                 
root      3446  0.0  1.8 544540 37144 ?        Ss   17:02   0:00 /usr/sbin/apache2 -k start                                                             
www-data  3449  0.1  1.9 550388 39796 ?        S    17:02   0:00 /usr/sbin/apache2 -k start                                                             
www-data  3454  0.0  1.0 547336 21532 ?        S    17:02   0:00 /usr/sbin/apache2 -k start                                                             
www-data  3457  0.0  1.8 548196 37864 ?        S    17:02   0:00 /usr/sbin/apache2 -k start                                                             
www-data  3458  0.0  1.0 547320 21428 ?        S    17:02   0:00 /usr/sbin/apache2 -k start                                                             
www-data  3462  0.0  1.7 550008 36264 ?        S    17:02   0:00 /usr/sbin/apache2 -k start                                                             
www-data  3465  0.0  1.8 550408 38160 ?        S    17:02   0:00 /usr/sbin/apache2 -k start                                                             
www-data  3466  0.0  1.9 550400 40512 ?        S    17:02   0:00 /usr/sbin/apache2 -k start                                                             
www-data  3467  0.0  1.0 547320 21416 ?        S    17:02   0:00 /usr/sbin/apache2 -k start                                                             
www-data  3468  0.0  1.7 548228 36236 ?        S    17:02   0:00 /usr/sbin/apache2 -k start                                                             
www-data  3520  0.0  0.9 546872 19964 ?        S    17:06   0:00 /usr/sbin/apache2 -k start                                                             
root      3526  0.0  0.0  14856  1036 pts/1    S+   17:06   0:00 grep --color=auto apache                                                               
root@theawsbiz:~# ps -aux | grep nginx                                                                                                                  
root      3529  0.0  0.0  14856  1092 pts/1    S+   17:06   0:00 grep --color=auto nginx                                                                

With those result about, I know that this VM is using Apache.

But, I have no idea how to check it via a Bash script. How would one go about and do that? I'm open to any suggestions at this moment.

Since you are trying to achieve this with grep and ps, you could do something like this:

if [[ `ps -acx|grep apache|wc -l` > 0 ]]; then
    echo "VM Configured with Apache"
if [[ `ps -acx|grep nginx|wc -l` > 0 ]]; then
    echo "VM Configured with Nginx"

Bash check if process is running or not on Linux / Unix, pgrep command – Looks through the currently running bash processes on For example, Apache or Nginx web server runs on Linux or Unix-like system to Determine whether a process is running or not using a shell script. The shell and Apache should find the interpreter using the path information on the first line of the script.) The first thing you see written by your program should be a set of HTTP headers, including the Content-Type , followed by a blank line.

ss command can tell you what process is listening on a port.

For example ss -tlnp | grep -E ":80\b" tells you what process is listening on tcp port 80. You can see it's apache or nginx.

How to find out if httpd is running or not via command line?, Most people run their httpd (Apache, Nginx, etc) through an init system. Obviously if you're running a different httpd, script or init system, you're going to have a wget --spider -S "http://localhost" 2>&1 | awk '/HTTP\// {print $2}' 200 So let's talk to an external server (ideally on a completely different connection, in another� For example, Apache or Nginx web server runs on Linux or Unix-like system to display web pages in the background. All running process in the background is called as Daemon. So Apache/Nginx is a class of processes that run continuously in the background, and we say nginx or httpd daemon is running on the server.

  1. You could curl against localhost and grep the headers
$ curl -v 2>&1 |grep -i server | awk -F: '{print $2}'


You can run the command in a subshell and get the output

 ❯ get_server_version=$(curl -v 2>&1 |grep -i server | awk -F: '{print $2}') 
 ❯ echo $get_server_version                                                                            

Or just run pgrep

 ❯ { pgrep nginx && server_version="nginx"; } || { pgrep apache  && server_version="apache"; } || server_version="unknown"

# On server running nginx
 ❯ echo $server_version

# On server with neither nginx nor apache
 ❯ echo $server_version

3 Ways to Check Apache Server Status and Uptime in Linux, Apache is a world's most popular, cross platform HTTP web server that is commonly used in Linux and Unix platforms to deploy and run web� Today, NGINX and NGINX Plus can handle hundreds of thousands of concurrent connections, and power more than 50% of the busiest sites on the web. NGINX as a Web Server. The goal behind NGINX was to create the fastest web server around, and maintaining that excellence is still a central goal of the project.

As curl does not always retrieve the type of webserver, you may use the following code locally on the server :

for webservice in gitlab apache nginx lighttpd; do 
    if `ps aux|grep -v grep|grep -q $webservice`; then 
        echo $webservice; 

Don't do the break statement if you have many values (gitlab is using nginx).

If you have netstat on the server (I think you can use /proc informations instead) :

netstat -naptu |grep :80 |awk '{print $NF}'|cut -d"/" -f2|uniq

For the port 80 or 443 for https.

Best regards

10 Most Used Nginx Commands Every Linux User Must Know, To install Nginx web server, use your default distribution package manager To check the version of Nginx web server installed on your Linux� Nginx vs Apache: which one provides faster solutions for your WordPress sites? 🚀 Check out our web server showdown! Click to Tweet Summary. In this article, I focused on Nginx vs Apache and explained the main architectural differences that helped Nginx gaining more traction and attention within the web server arena.

linux script to check if a service is running and start it, if it's stopped , Here is a simple script that will check if your specified service is when apache is stopped and you execute the script from the console, I am new to Linux technology and I want to workout for my web server issue. So need shell script to restart those services from servers by automating without manully� But creating a scalable and high‑performance web server or ADC requires many of the same techniques. In many environments, one reason to deploy an ADC is to mitigate performance problems with the web server. By combining the ADC and web server into a single tool, NGINX is a really a new type of product for web application delivery, providing

9 Popular Nginx Commands You Should Know, Check out these 9 popular Nginx commands to help you out. Nginx is one of the most popular web servers in the world. So whether you're currently using it or not, chances are, if you're a web developer chances are A virtual host is an Apache term, however, is commonly used by Nginx users as well. Apache and Nginx are both powerful web servers that can reliably host web content on the internet. While Apache is the currently the most popular web server in the world, Nginx is rapidly gaining converts due to its low resource usage.

CommandLine, This tutorial shows you how to start, stop, and control NGINX from the command Web Server Load Balancing with NGINX Plus For example, /usr/bin/nginx -s stop will stop the NGINX server. What happens is that when NGINX receives the HUP signal, it tries to parse the configuration file (the specified one, if present, � Documentation explaining how to configure NGINX and NGINX Plus as a web server, reverse proxy, or application gateway. Your Cookie Settings Site functionality and performance.

  • Cant we do wc -l on grep and see if there are results returned to find whether that process runs?
  • @Sonny wc -l > 1 or > 0 ?
  • Technical yes, `ps -acx|grep apache|wc -l` > 0 , but checking with headers will be much better
  • I think your comment is exactly what I am looking for, you shoud answer it.