简体   繁体   English

如果一台服务器安装了nginx和apache,我如何找出它用于其网站的服务器?

[英]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.

相关问题 你怎么知道安装了什么包`apache2`作为依赖? - How do you find out which packages installed has `apache2` as its dependency? 如何找出ElasticBeanStalk中使用的Apache或Nginx Web服务器的版本? - How do I find out what version of Apache or nginx web server is used in ElasticBeanStalk? 如何同时在 Nginx 和 Apache 上托管网站(部分) - How do I host a website (parts of it) on Nginx and Apache at the same time 在OSX 10.9中,Apache使用与终端不同的php.ini。 如何更改一个终端使用哪个? - In OSX 10.9, Apache is using a different php.ini then terminal. How do I change which one terminal uses? 我在Centos 7服务器上安装了两个PHP副本,如何确定Apache正在使用哪个PHP? - I have two copies of PHP installed on my Centos 7 server how do I tell which is being used by apache Nginx代理到具有自我证书的上游apache服务器 - nginx proxying to upstream apache server which has self-certificate 如何在目录中找到有效的Apache配置设置 - How do I find out an effective apache config setting in a directory 在运行Nginx的反向代理的apache上运行的服务器上安装Nodejs应用 - Install Nodejs app on server running on apache which uses reverse proxy with nginx nginx(已安装php)proxy_pass指定目录到apache服务器(使用php-fpm)失败 - nginx (has php installed ) proxy_pass specified directory to apache server( with php-fpm) failed 我如何慢慢开始使用nginx和/或Apache? - How I do slow start with nginx and/or Apache?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM