THAPA TECHNICAL

HOUSE OF WEB DEVELOPERS AND TECHNOLOGY.

How to host React JS Website live on VPS Server

First, we need to buy the Domain and then go to the Domain DNS/NAMESERVERS settings and follow the steps below

1: Add A record 

2: Add CNAME  

A DNS (Domain Name System) is a system that converts human-friendly domain names, such as "example.com", into IP addresses that computers can understand, such as "192.0.2.1". DNS allows users to access a website or other online resources by typing a domain name into their browser, rather than having to remember and enter the corresponding IP address.

A type A record is one of the types of DNS records that are used to map a hostname to an IP address. It is the most basic and fundamental type of DNS record. When a user's computer or device makes a request to access a website or other online resource, the request is sent to a DNS server, which looks up the domain name in question and returns the corresponding IP address. The returned IP address is then used to connect to the appropriate server and load the website or other resources.

A CNAME (Canonical Name) record, on the other hand, is used to create an alias for a hostname. It is used to map an alias hostname to the real hostname. A CNAME record is useful in situations where you want to have multiple hostnames point to the same website or resource without having to maintain multiple IP addresses. For example, you might have a web server running on "www.example.com" and want users to be able to access the website using just "example.com". In this case, you would create a CNAME record that maps "example.com" to "www.example.com". This way, when a user types "example.com" into their browser, the DNS server will look up the CNAME record and return the IP address for "www.example.com", which is the real hostname for the website.

In summary, Type A records are used to map a hostname to an IP address, while CNAME records are used to create an alias for a hostname, allowing multiple hostnames to point to the same website or resource.


Why and What is puTTy?


-> Most of the hosting services, both online and offline are built on LINUX OS, rightly so because it provides better safety for client data. Especially when thousands of clients' data are stored in a single place safety is the first priority.


-> However this poses a greater challenge for non-LINUX OS users to deal with. Here come the third-party applications like PuTTy which enables non-Linux users to install this particular software(PuTTy), And interact with Linux servers from a non-Linux OS


-> Interface of PuTTy is similar to a windows terminal, however, the user needs to be aware of Linux commands to interact with it


-> PuTTy provides various File transfer features like FTP and SFTP depending on users' security requirements.


▶ VPS Server link: https://hostinger.com/thapa7
▶ Also, use the THAPA7 coupon code for an extra 10% Discount.


How to host the Domain on any VPS Server


1. create a configuration file for the main domain  

   `nano /etc/nginx/sites-available/yourDomain.com`


Here is the meaning of this command

This command opens the text editor "nano" and opens the file "/etc/nginx/sites-available/domain.com" for editing. The file "/etc/nginx/sites-available/domain.com" is likely a configuration file for the domain "domain.com" on an Nginx web server. The file contains settings and rules for how the server should handle requests for that specific domain.

Imagine you are setting up a website for "example.com" on a server that is running Nginx. To configure Nginx for this website, you would create a configuration file in the directory "/etc/nginx/sites-available" and name it "example.com". This file would contain information such as the server's IP address, the root directory for the website, and any other necessary settings


---


Inside that put below content


    server {

    listen 80;

    root /var/www/html;

    index index.html index.htm index.nginx-debian.html;

            server_name yourDomain.com www.yourDomain.com;

            location / {

                    proxy_pass http://localhost:3000;

                    proxy_http_version 1.1;

                    proxy_set_header Upgrade $http_upgrade;

                    proxy_set_header Connection 'upgrade';

                    proxy_set_header Host $host;

                    proxy_cache_bypass $http_upgrade;

                }

    }


---


2. Create a symbolic or soft link  

   `ln -s /etc/nginx/sites-available/yourDomain.com /etc/nginx/sites-enabled/yourDomain.com`


This command creates a symbolic link (also known as a "soft link") from the file "/etc/nginx/sites-available/domain.com" to the file "/etc/nginx/sites-enabled/domain.com".

The ln command creates a link to the file. The -s option specifies that it is a symbolic link.

The file "/etc/nginx/sites-available/domain.com" is likely a configuration file for the domain "domain.com" on an Nginx web server. The file contains settings and rules for how the server should handle requests for that specific domain.

The sites-enabled folder is where nginx looks for the configuration file to use. So, this command is likely used to enable the configuration for the domain "domain.com" on the Nginx web server.


---


3. check if the file content is right or not using test configuration.  

   `sudo nginx -t`


This command runs the command nginx -t with superuser (sudo) privileges. The -t flag stands for "test configuration."


When you run this command, Nginx will check the syntax of the configuration files in the directory specified in its main configuration file, typically at /etc/nginx/nginx.conf. If the syntax is correct, the command will return the message "nginx configuration test is successful" and exit with a return code of 0. If there are any issues with the configuration, such as a missing semicolon or a misspelled directive, the command will return an error message detailing the problem and exit with a non-zero return code.


This command is typically used to check the configuration files before reloading or restarting the server to make sure that the new configuration can be loaded without errors.

---


4. restart the nginx server  

   `sudo systemctl restart nginx`


This command restarts the Nginx service using the systemctl command with superuser (sudo) privileges.


systemctl is a command-line utility used to control and manage systemd services and daemons.

restart is the action that tells systemctl to stop the currently running instance of the service and start it again.


When you run this command, systemctl will stop the currently running instance of the Nginx service and start it again. This can be useful if you have made changes to the Nginx configuration files and want to apply those changes without having to reboot the entire system.


It's important to note that this command will only work on systems that use systemd as the init system, which is the default init system for many modern Linux distributions.


Also, it's worth noting that restarting the service may cause a brief interruption in service, so this command should be used with caution if the service is critical to the system's operation.

---


5. generate SSL  

   `certbot`


Certbot is a command-line tool for automating the process of obtaining and renewing SSL/TLS certificates from the Let's Encrypt certificate authority. It provides an easy way to obtain and install free, valid SSL/TLS certificates on web servers, which can be used to secure communication between a website and its users.


Let's Encrypt is a free, automated, and open certificate authority that provides domain-validated (DV) certificates. Certbot is the official client software that interacts with Let's Encrypt's servers to automatically obtain and install the certificates.


Certbot can be used to obtain and install SSL/TLS certificates for multiple web servers, including Apache, Nginx, and others. It can also be used to automatically renew the certificates before they expire, ensuring that the website's SSL/TLS certificate is always valid.


Certbot is typically run from the command line and is available for the most popular operating systems, including Linux, macOS, and Windows.

---