How can I check if current web server is NGINX or Apache using bash script?
- You could curl against localhost and grep the headers
$ curl -v api.company.co.ke 2>&1 |grep -i server | awk -F: '{print $2}'nginx/1.10.3You can run the command in a subshell and get the output ❯ get_server_version=$(curl -v api.company.co.ke 2>&1 |grep -i server | awk -F: '{print $2}') ❯ echo $get_server_version nginx/1.10.3
Or just run pgrep
❯ { pgrep nginx && server_version="nginx"; } || { pgrep apache && server_version="apache"; } || server_version="unknown"# On server running nginx ❯ echo $server_versionnginx# On server with neither nginx nor apache ❯ echo $server_versionunknown