How to Set Up Nginx Server Blocks on CentOS 7

To set up multiple websites on a single Nginx server running on CentOS 7, follow these steps:

Step 1 : Ensure that Nginx is installed on your CentOS 7 system. You can check this by running:

Step 2 : Create a directory for your website example.com and an index file to serve as the homepage:

Add the following HTML content to the index.html file:

Step 2 : Set the correct permissions for the web directory to ensure Nginx can access the files:

Step 3 : Create a new server block configuration file for example.com:

Add the following configuration to the file:

Step 4 : If SELinux is enabled on your system, run the following command to ensure Nginx can access the files:

Step 5 : Test the Nginx configuration to make sure there are no syntax errors:

Step 6 : Restart the Nginx service to apply the changes:

Step 7 : Ensure that your firewall allows HTTP traffic:

Step 8 : Test Your Configuration

Visit http://example.com in your browser. You should see your welcome message.

Congratulations! You have successfully set up an Nginx server block on CentOS 7. Repeat these steps for additional websites.