How to Set Up Nginx Server Blocks on Ubuntu 23.10

Setting up Nginx server blocks, also known as virtual hosts, allows you to host multiple websites on a single server. Here's a step-by-step guide to set up Nginx server blocks on Ubuntu 23.10:

Step 1 : Nginx installed on your server. If not, you can install it by running the following command:

Step 2 : Create Directory Structure:

Start by creating a directory structure to store your website files. For example, create a directory for each website you want to host:

Step 3 : Set Permissions:

Set the appropriate permissions for the directories you just created:

Step 4 : Create Sample HTML Pages:

Create a simple HTML file for each website as a placeholder:

Step 5 : Create Nginx Server Block Configuration:

Create separate Nginx server block configuration files for each site. These files are typically located in the /etc/nginx/sites-available/ directory:

Add the following configuration, replacing the placeholders with your own values:

Repeat the process for the second site:

Step 6 : Create Symbolic Links:

Create symbolic links to enable the server blocks:

Step 7 : Test Nginx Configuration:

Ensure that there are no syntax errors in your Nginx configuration:

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

Step 8 : Update DNS Records

Finally, make sure your domain's DNS records point to the correct server IP address.

Step 9 : Verify Configuration by Accessing Websites:

Open your web browser and navigate to the URLs associated with your configured server blocks, such as http://example1.com and http://example2.com. If everything is set up correctly, you should see the respective HTML pages you created earlier.

You have successfully set up Nginx server blocks on your Ubuntu 23.10 server. This allows you to host multiple websites on a single server, each with its own directory structure and configuration.