We have a lot of servers and vhosts and some of them use nignx, some httpd or apache for their domains. I want to write an ansible script that pulls the information out on what web server the vhost uses for its site, the problem is that a lot of them have all 3 web servers installed but only one is actually used for the site to run (others might have an active status).
I mean, I don’t even know where to begin. A simple example of a bash script would be nice that accurately outputs the web server of the vhost.
2
Answers
how about checking the ports 80 or 443 which process is using them:
and for port 443:
The output will be one of those lines:
And you can write an ansible task to run this cmd
Q: “
If a server has nginx and apache installed, how do I find out which one is used for the website?
“A: Given a “website” we know the IP address and port. Then the question is: What daemon is running at www_ip host and www_port?
Let’s use
lsof
and print the first item on the list. The play below (as an example nginx is listening at port 8080)gives
Notes