[英]If a server has nginx and apache installed, how do I find out which one it uses for its website?
We have a lot of servers and vhosts and some of them use nignx, some httpd or apache for their domains. 我们有很多服务器和虚拟主机,其中一些使用nignx,某些httpd或apache作为其域。 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).
我想编写一个Ansible脚本,将信息提取到虚拟主机用于其站点的Web服务器上,问题是它们中有很多都安装了3个Web服务器,但实际上只有一个用于运行该站点(其他可能处于活动状态)。
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.
一个bash脚本的简单示例很不错,它可以准确地输出虚拟主机的Web服务器。
how about checking the ports 80 or 443 which process is using them: 如何检查端口80或443使用哪个进程:
sudo netstat -ntlp | grep '0.0.0.0:80' | awk '{print $7}'
and for port 443: 对于端口443:
sudo netstat -ntlp | grep '0.0.0.0:443' | awk '{print $7}'
The output will be one of those lines: 输出将是以下行之一:
xx/httpd # for apache
xx/nginx # for nginx
And you can write an ansible task to run this cmd 您可以编写一个ansible任务来运行此cmd
Q: " If a server has nginx and apache installed, how do I find out which one is used for the website?
" 问:“
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. 答:给定“网站”,我们知道IP地址和端口。 Then the question is: What daemon is running at www_ip host and www_port?
然后的问题是:在www_ip主机和www_port上运行什么守护程序?
Let's use lsof
and print the first item on the list. 让我们使用
lsof
并打印列表中的第一项。 The play below (as an example nginx is listening at port 8080) 下面的播放(例如,nginx正在端口8080上监听)
- hosts: www_ip
vars:
www_port: 8080
tasks:
- shell: "lsof -i :{{ www_port }}|
grep LISTEN|
cut -d ' ' -f 1"
register: result
- debug:
msg: "{{ result.stdout_lines|first }}"
gives 给
ok: [www_ip] => {
"msg": "nginx"
}
Notes 笔记
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.