Skip to content
Menu
TechFacts007.in
  • Information Zone
  • Reviews
    • Apps Reviews
    • PC’s
  • Gadgets
  • Hosting
    • Domain and Hosting
      • cPanel
    • WordPress
  • More
    • Tech Facts
    • Tips & Tricks
TechFacts007.in
nginx logo
May 21, 2023May 21, 2023

Setting Up NGINX on Ubuntu Server and Activating a Domain on NGINX Server

NGINX is a powerful and widely used web server that excels in delivering high-performance web content. In this article, we will guide you through the process of setting up NGINX on an Ubuntu server and activating a domain on the NGINX server. We will cover the installation, configuration, and management of NGINX, along with the necessary steps to enable your domain on the server. Additionally, we will explore the commands required to start, restart, and check the status of NGINX.

nginx image

Installation of NGINX on Ubuntu

NGINX is a popular web server known for its high performance, scalability, and flexibility. In this guide, we will walk you through the process of installing NGINX on a server using Ubuntu as the operating system. The following steps explain how to install NGINX using commands.

 

Step 1: Update the System.

Before installing any software, it is essential to update the system to ensure that you have the latest packages and security patches. Open the terminal on your server and run the following command:

sudo apt update && sudo apt upgrade

 

Step 2: Install NGINX

To install NGINX on Ubuntu, use the apt package manager. Run the following command in the terminal:

sudo apt install nginx

This command will install NGINX and its dependencies. During the installation, you might be prompted to confirm the installation by pressing ‘Y’ and then press Enter.

 

Step 3: Start NGINX

Once NGINX is installed, it will automatically start running. However, if it is not started for any reason, you can manually start it using the following command:

sudo systemctl start nginx

 

To check if NGINX is running, you can use the following command:

sudo systemctl status nginx

 

If NGINX is active and running, you will see an “active (running)” status in the output.

 

Step 4: Testing NGINX

To verify that NGINX is correctly installed and running, open a web browser and enter your server’s IP address or domain name. You should see the default NGINX welcome page if everything is set up correctly.

 

Step 5: Adjusting Firewall Settings

By default, NGINX listens on port 80 for HTTP traffic. Ensure that your server’s firewall allows inbound traffic on this port. If you are using UFW, a simple command to allow HTTP traffic is:

sudo ufw allow 'Nginx HTTP'

 

Step 6: Additional Configuration

NGINX’s main configuration file is at /etc/nginx/nginx.conf. You can modify this file to customize NGINX’s behavior according to your needs. However, be cautious when making changes to avoid misconfigurations that could affect NGINX’s performance or security.

 


 

hosting image

Hosting a Website on NGINX Server

Step 1: Create a Website Directory

First, create a directory where your website files will reside. You can choose any location, but a common directory is /var/www/. Use the following command to create the directory:

sudo mkdir -p /var/www/example.com

 

Replace “example.com” with your actual domain or website name.

 

Step 2: Configure NGINX

Next, configure NGINX to host your website. Open the NGINX configuration file using a text editor:

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

 

Replace “example.com” with your domain or website name.

Inside the file, add the following configuration:

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

    location / {
        try_files $uri $uri/ =404;
    }
}

NOTE: If you want to set up react js web app you should configure nginx to serve files from the build directory of react js web app. See the below example.

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

    location / {
        try_files $uri $uri/ =404;
    }
}

 

Save the file and exit the text editor.

 

Step 3: Enable the Website

Create a symbolic link from the configuration file in the sites-available directory to the sites-enabled directory to enable your website. Use the following command:

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

 

Step 4: Test Configuration and Restart NGINX

Before restarting NGINX, it’s essential to test the configuration to ensure there are no syntax errors. Run the following command:

sudo nginx -t

 

If the test is successful, you should see “syntax is okay” in the output. If there are any errors, review your configuration file for typos or mistakes.

Finally, restart NGINX to apply the changes:

sudo systemctl restart nginx

 

Step 5: Upload Website Files

Upload your website files to the directory you created earlier (/var/www/example.com). You can use FTP, SCP, or any other file transfer method to copy your website files to the server.

 

Step 6: Access Your Website

Open a web browser and enter your domain or website name (e.g., http://example.com). You should see your website’s content if everything is set up correctly.

 


 

Also Read: Upload WordPress Plugins and Themes Using FTP

Nginx Vs Apache

Post Views: 37

1 thought on “Setting Up NGINX on Ubuntu Server and Activating a Domain on NGINX Server”

  1. Pingback: NGINX vs. Apache: Exploring the Differences and Choosing the Right Web Server - TechFacts007.in

Leave a Reply Cancel reply

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

Trending

  • Tech Facts
    52.376552,5.198303(Dead Body Found) Google Map
  • Information Zone
    Create Sitemap for React.Js Web App – Sitemap.xml for react app
  • Information Zone, Programming Languages, Tutorials
    React Hook To Check If User Has Changed/Minimize the Browser Tab
  • Codes, Programming Languages
    Find out if you can reach the last tile – Program Code
  • How to, Information Zone, Tips & Tricks
    Encrypt Javascript and CSS Code – Hide Original Code from Users
  • Tech Facts
    In 1956, 5 megabytes (5MB) of data weighed a Ton.
  • How to, Information Zone, Tips & Tricks
    Download any paid Software. Get any software free for lifetime
  • PC's, Tips & Tricks
    Mount and Unmount Virtual Hard Disk (CMD Command and batch File Method)

Recent Posts

  • Worker Threads in JavaScript: Enhancing Performance with Parallelism July 31, 2023
  • Create Sitemap for React.Js Web App – Sitemap.xml for react app May 27, 2023
  • The Importance of Sitemap.xml: Enhancing Website Visibility and SEO May 27, 2023
  • Web Page Generation – Difference between SSR, CSR and SSG May 26, 2023
  • React.js vs. Next.js – Choosing the Right Framework for Your Web Development Needs May 26, 2023
  • NGINX vs. Apache: Exploring the Differences and Choosing the Right Web Server May 21, 2023
  • Setting Up NGINX on Ubuntu Server and Activating a Domain on NGINX Server May 21, 2023
  • Functional Component vs Class Component in React.Js January 18, 2023
  • React.Js Lifecycle Methods January 18, 2023
  • What is componentDidMount and useEffect with Example January 18, 2023

Categories

  • Apps Reviews (4)
  • Gadgets (4)
  • Hack With Us (2)
  • Hosting (12)
    • Domain and Hosting (7)
      • cPanel (5)
    • Wordpress (5)
  • How to (11)
  • Information Zone (65)
  • PC's (7)
  • Product Reviews (11)
  • Programming Languages (11)
    • Codes (5)
    • Tutorials (6)
  • Smart Phones (8)
  • Tech Facts (13)
  • Tips & Tricks (13)

Browse By Date

September 2023
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  
« Jul    

More

Contact Us
Privacy Policy
About Us
About Admin

Advertisement

Other Sites

ShanuTheWebDev.in
QrCode.ShanuTheWebDev.in
©2023 TechFacts007.in | Powered by WordPress and Superb Themes!