How to List all vhosts in Nginx in Linux?
In this section, we will see how we can list all vhosts in Ngnix in Linux. So follow the below steps along with proper command execution to see the detailed list of all vhosts in Ngnix in Linux:
Step 1: Open the Terminal
Firstly, we need to launch the terminal on our Linux system, we can launch by using the Application Menu or by using the Keyboard Shortcut as “CTRL + ALT + T“.
Step 2: Navigate to the Nginx Configuration Directory
Once the terminal has been launched, we need to navigate to the Nginx configuration directory which is mainly stored in the /etc/nginx. We can execute the below cd command to naivete to the required directory.
cd /etc/nginx
Step 3: View the Contents of the sites-available Directory
Now, in the sites-available directory, we will find configuration files for each virtual host. We can use the ls command to list the files.
ls sites-available
We can see virtual host configuration files in the below output screenshot, and the default is the default configuration.
Step 4: View the Contents of the Configuration Files
If we want to view the contents of a specific configuration file, then we can view it by using the cat command. You need to replace w3wiki.org with the actual filename of the virtual host you want to inspect. This command will display the content of the specified configuration file.
cat sites-available/w3wiki.org
Step 5: Verify Configuration Syntax
Before applying the changes, it’s a good practice to test the Nginx configuration for syntax errors. If there are no errors, you should see a message indicating that the configuration file test is successful.
sudo nginx -t
Step 6: Restart Nginx
Apply the changes by restarting the Nginx service. The below command restarts the Nginx service to apply the new configuration with root privileges.
sudo systemctl restart nginx
Step 7: Verify Changes in nginx
To verify that the changes have taken effect, we can use the nginx -T command. This command displays the entire Nginx configuration
sudo nginx -T
How to List All vhosts in nginx in Linux
On Ngnix Web Server on Linux, the virtual host or vhost refers to the task of hosting various websites on a single server by configuring various server blocks that are associated with the specific domain or IP address. This server mainly blocks allo Ngnix to handle incoming requirements and then direct them to the proper website which is based on the configuration. If we want to see the list of all the vhosts in Nginx in Linux, then we can perform the steps which are discussed in the following sections.