NGINX Installation and Website Configuration

Posted by

In this blog, we’ll provide a clear and concise summary of the server setup and NGINX installation process.

Operating System: Debian 12

Ports Opened: 22, 80, and 443

To ensure your system is up to date, follow these steps:

  1. Update the package list:

sudo apt update -y

  1. Upgrade installed packages:

sudo apt upgrade -y

Now, let’s proceed with the NGINX installation:

  1. Install NGINX (the Web Server):

sudo apt install -y nginx

  1. Reboot the server:

sudo reboot

After the server restarts, enable NGINX and check its status:

  1. Enable NGINX:

systemctl enable nginx

  1. Check NGINX status:

systemctl status nginx

With these steps, you’ll have a fully functional NGINX web server ready to host your website, type in the IPaddress of your serve in your browser and you should see this page.

After installing NGINX, you’ll need to create a custom configuration file to serve your website. Start by disabling the default NGINX configuration:

unlink /etc/nginx/sites-enabled/default

Next, create a new NGINX configuration file for your website using a text editor like Nano. For example, if your website is “test.techtips.com.au,” you would use the following command:

nano /etc/nginx/sites-available/test.techtips.com.au

In the editor window, enter the following configuration. You can disable IPv6 by adding a comment (#) before the relevant line:

server {

    listen 80; 

    # listen [::]:80;

    server_name test.techtips.com.au;

    root /var/www/test.techtips.com.au;

    index index.html;

    location / { 

        try_files $uri $uri/ =404;

    } 

}

After saving and closing the file, make your website go live by linking the configuration file from sites-available to sites-enabled:

ln -s /etc/nginx/sites-available/test.techtips.com.au /etc/nginx/sites-enabled/

With these steps, you’ve created a custom NGINX configuration file and activated it to serve your website.

After creating or modifying an NGINX configuration file, it’s crucial to verify its correctness before reloading or restarting the service. You can use the nginx -t command to perform a syntax check on the configuration files:

nginx -t

If the configuration is correct, you’ll see a message indicating that the syntax is OK, similar to the following:

If you encounter an error, double-check your configuration file for typos, missing characters, or any incorrect syntax. Make necessary corrections, and rerun the nginx -t command until it returns a successful message. Once the configuration syntax is verified, you can proceed with reloading or restarting the NGINX service to apply the new configuration.

After modifying your NGINX configuration, you’ll need to restart the NGINX service for the changes to take effect. Use the following command to accomplish this:

systemctl restart nginx.service

Once NGINX restarts, your new configuration will be applied.

To set up your website, start by creating a directory for it within the /var/www/ directory. Continuing with the example of “test.techtips.com.au,” you can create the directory as follows:

mkdir /var/www/test.techtips.com.au

With this command, you’ve established the necessary directory structure for your website’s content. You can now upload your website’s HTML, CSS, JavaScript, and other assets to this directory. Ensure that the appropriate user and group have access to these files based on your server’s security and permission settings.

Now that you have the directory structure set up for your website, you can create a simple HTML landing page. Use Nano to create and edit the index.html file within your website’s directory (e.g., /var/www/test.techtips.com.au/index.html).

Enter the following HTML content to create a basic “Hello, World!” page:

<!doctype html>

<html>

<body>

    <h1>Hello World !!!</h1>

    <p>This is a test website demonstrating NGINX Installation and serving a webpage</p>

</body>

</html>

After saving and closing the file, you can use a web browser to access your website. Ensure that you’ve properly configured the domain’s A record to point to your test server’s IP address.

Navigate to your website’s address (e.g., “http://test.techtips.com.au”), and you should see the “Hello, World!” page displayed. This confirms that NGINX is successfully serving your website’s content.

Congratulations! You’ve successfully completed the NGINX web server installation, configuration, and setup of a basic website. By following the provided steps, you’ve accomplished the following:

  1. Installed NGINX on your Debian 12 server.
  2. Created a custom NGINX configuration file to serve your website.
  3. Set up the necessary directory structure for your website content.
  4. Created a simple HTML landing page for your website.
  5. Verified that NGINX is correctly serving your website’s content.

With these fundamental steps, you’ve established a solid foundation for hosting and serving web content using NGINX. You can now explore more advanced NGINX configuration options, security settings, and other optimizations to better suit your specific website requirements.

Leave a Reply

Your email address will not be published. Required fields are marked *