How to Set Up Nginx Server Blocks on Rocky Linux 9

To set up multiple websites on a Rocky Linux 9 server, you can use Nginx server blocks, also known as virtual hosts. This allows you to host multiple domains on a single server.

Step 1 : Ensure that Nginx is installed on your Rocky Linux 9 system by running the following command:

Step 2 : Create a directory for your website, for example, example.com, and an index file within it:

Step 3 : Set the appropriate permissions for the web directory:

Step 4 : Create Nginx Configuration

Create a new Nginx configuration file for your website:

Add the following basic configuration:

Step 5 : If SELinux is enabled, set the appropriate context for the web directory:

Step 6 :Test the Nginx configuration for syntax errors:

Step 7 : If the test is successful, restart Nginx to apply the changes:

Step 8 : Visit the Domain

Open a web browser and navigate to your domain, e.g., http://example.com, to test your website.

Congratulations! You have successfully set up Nginx server blocks on Rocky Linux 9, allowing you to host multiple websites on a single server.