Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I list all vhosts in nginx

Tags:

linux

shell

nginx

Is there a command that will list all vhosts or servers running under nginx on CentOS? I would like to pipe the results to a text file for reporting purposes.

I'm looking for something similar to this command that I use for Apache:

apachectl -S 2>&1 | grep 'port 80'

like image 988
Corgalore Avatar asked Sep 04 '15 14:09

Corgalore


People also ask

Where is nginx virtual hosts file?

Virtual host config files are typically located in the /etc/nginx/sites-available directory. You may also notice that your server has a /etc/nginx/sites-enabled folder, which is where file shortcuts (symbolic links) are placed.

Can nginx have multiple servers?

If you are using a dedicated server / VPS and want to host multiple applications on a separate domain and a single server then you will need to host multiple websites on a single server. You can achieve this with Apache / Nginx virtual hosting. Virtual hosting allows you to use a single VPS to host all your domains.

What is server_name _ in nginx?

Virtual server selection. Optimization. Compatibility. Server names are defined using the server_name directive and determine which server block is used for a given request. See also “How nginx processes a request”.

Where is nginx server block?

Nginx server blocks are located in the /etc/nginx/sites-available directory. The default Nginx server block is /etc/nginx/sites-available/default which serves the default HTML file at /var/www/html/index.


1 Answers

starting from version 1.9.2 you can do:

nginx -T 

show complete nginx configuration

nginx -T | grep "server_name " #include the whitespace to exclude non relevant results 

show you all server names

like image 186
Alessio Avatar answered Nov 14 '22 09:11

Alessio