How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 14.04 LTS

How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 14.04 LTS

How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 14.04 LTS

Introduction

Nginx is a popular web server used by many websites and web applications. It is known for its high performance and low resource usage. Server Blocks, also known as Virtual Hosts, allow Nginx to host multiple websites on the same server. In this tutorial, we will learn how to set up Nginx Server Blocks on Ubuntu 14.04 LTS.

Prerequisites

Before we begin, make sure you have the following:

  • Ubuntu 14.04 LTS server
  • Nginx installed

Step 1: Create Server Block Directory

First, we need to create a directory to store our server block configurations:

sudo mkdir /etc/nginx/sites-available
sudo mkdir /etc/nginx/sites-enabled

Step 2: Create Server Block Configuration File

Next, we need to create a new server block configuration file for each website we want to host. Let's create a configuration file for example.com:

sudo nano /etc/nginx/sites-available/example.com

Inside the file, add the following configuration:

server {
    listen 80;
    server_name example.com;
    root /var/www/example.com/public_html;
    index index.html;
}

Save and exit the file.

Step 3: Enable Server Block

Now, we need to enable the server block by creating a symbolic link from the sites-available directory to the sites-enabled directory:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

Step 4: Restart Nginx

Finally, we need to restart Nginx to apply the changes:

sudo service nginx restart

Conclusion

In this tutorial, we learned how to set up Nginx Server Blocks (Virtual Hosts) on Ubuntu 14.04 LTS. With this setup, we can host multiple websites on the same server using a single instance of Nginx.

Keywords: Nginx, Ubuntu 14.04, Server Blocks, Virtual Hosts, Web Server.

Комментарии

Популярные сообщения из этого блога

How To Modify CSS Classes in JavaScript

How To Backup MySQL Databases on an Ubuntu VPS

How To Backup PostgreSQL Databases on an Ubuntu VPS