Deploy your website on an Ubuntu VPS with a Real Domain in Easy step

0 0 0

Người đăng: Nam Trần

Theo Viblo Asia

Part 1: Setting Up the Basic Environment

1. Introduction

Hello, my name is Nam, and I am currently a third-year AI major at FPT University. I have a strong passion for technology and have successfully deployed a project on an Ubuntu VPS platform. Through this article, I hope to guide you step by step in bringing your website closer to users in a professional and efficient manner.

1.1 What is VPS Ubuntu ?

VPS (Virtual Private Server) is an independent virtual server that operates within a larger physical server. Unlike traditional shared hosting, VPS offers dedicated and separately allocated resources.

Outstanding Advantages of VPS:

  • Dedicated Resources: CPU, RAM, and storage are allocated exclusively, ensuring stable performance.
  • Full Control: Root access allows customization of the server to meet specific needs.
  • Scalability: Easily upgrade or downgrade resources as required.
  • High Security: An isolated environment enhances security.

2. Preparation

2.1 System Requirements

  • A VPS running Ubuntu Server (latest LTS version)
  • At least 1GB of RAM
  • Minimum 20GB of storage
  • Stable internet connection

2.2 Installing the Ubuntu Operating System

To install Ubuntu accurately and efficiently, you can refer to the official guide from the Ubuntu website or watch this video tutorial on YouTube by Anh Việt Nguyễn AI. These resources provide step-by-step instructions, from downloading the ISO file and creating a bootable USB stick to completing the installation directly on your server or computer.

I recommend using Ubuntu 20.04.6 LTS (Focal Fossa). This version is stable, has long-term support (LTS), and in my experience, it integrates well with libraries and is less prone to errors compared to other versions.

2.3 Checking Connectivity

Before proceeding with the next steps, ensure that your VPS has a stable internet connection. You can verify this by pinging a popular website, such as Google:

ping -c 4 google.com
Output Example: namhost@server-host-839:~$ ping -c 4 google.com
PING google.com(hkg07s48-in-x0e.1e100.net (2404:6800:4005:80a::200e)) 56 data bytes
64 bytes from hkg07s01-in-x0e.1e100.net (2404:6800:4005:80a::200e): icmp_seq=1 ttl=58 time=45.2 ms
64 bytes from hkg07s01-in-x0e.1e100.net (2404:6800:4005:80a::200e): icmp_seq=2 ttl=58 time=45.4 ms
64 bytes from hkg07s01-in-x0e.1e100.net (2404:6800:4005:80a::200e): icmp_seq=3 ttl=58 time=44.6 ms
64 bytes from hkg07s01-in-x0e.1e100.net (2404:6800:4005:80a::200e): icmp_seq=4 ttl=58 time=45.3 ms --- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 44.557/45.115/45.430/0.332 ms

4 packets transmitted, 4 received, 0% packet loss: This result indicates that all packets were successfully sent and received, confirming a stable internet connection. Now you’re ready to move on to the next step.

2.4 Updating the System

To ensure system security and optimal performance, it’s important to update all packages. You can do this by running the following commands:

sudo apt update && sudo apt upgrade -y

3. Environment Setup

3.1 Installing Nginx

Nginx is a high-performance, lightweight web server widely used in modern web applications. To install and configure Nginx on your VPS, follow these steps:

  1. Step 1: Install Nginx

    sudo apt update
    sudo apt install nginx -y
    
  2. Step 2: Configuring the Firewall

    Before checking Nginx, you need to adjust the firewall settings to allow access to the service. When you install Nginx, it automatically registers as a service with ufw, making it easy to grant access to Nginx.

    To list the application profiles that ufw supports, use the following command:

    sudo ufw app list
    
    Output: Available applications: Nginx Full Nginx HTTP Nginx HTTPS OpenSSH
    

    If ufw is not installed run this command and enable the firewall (if not already enabled), use the following:

    sudo apt-get install ufw
    sudo ufw enable
    sudo ufw status
    

The displayed results will include:

  • Nginx Full: Allows ports 80 (HTTP) and 443 (HTTPS).
  • Nginx HTTP: Allows only port 80 (HTTP).
  • Nginx HTTPS: Allows only port 443 (HTTPS).
  • OpenSSH: Allows SSH connections (port 22).
  1. Step 3: Configuring Firewall Rules

    1. Activate the most restrictive firewall profile that still allows the traffic you have previously configured. This helps protect your system from unwanted threats by only opening the ports necessary for the operation of your application. For example:
    • If you're only using HTTP traffic, you can enable the Nginx HTTP profile:
      sudo ufw allow 'Nginx HTTP'
      
    • If you're using both HTTP and HTTPS traffic, you can enable the Nginx Full profile:
      sudo ufw allow 'Nginx Full'
      
    • Then, check the current status of the firewall to ensure that the correct rules are applied:
      sudo ufw status
      
      Output: namhost@server-host-839:~$ sudo ufw status
      Status: active To Action From
      -- ------ ---- Nginx HTTP ALLOW Anywhere Nginx HTTP (v6) ALLOW Anywhere (v6)
      
  2. Step 4: Starting and Enabling Nginx

    sudo systemctl start nginx
    sudo systemctl enable nginx #Enable Nginx to start automatically on boot
    sudo systemctl status nginx
    
    namhost@server-host-839:~$ systemctl status nginx
    ● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2024-11-25 08:09:39 +07; 6h ago Docs: man:nginx(8) Main PID: 874 (nginx) Tasks: 9 (limit: 4470) Memory: 14.1M CGroup: /system.slice/nginx.service ├─874 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; ├─875 nginx: worker process
    

    After completing the installation, you can access the website through the IP address of your VPS, or by using http://localhost or http://127.0.0.1/ if you're working directly on the server.

    If you see the Nginx welcome page, congratulations, you have successfully installed Nginx! 🎉

    This confirms that Nginx is running correctly and serving content on your server.

    You can also check if your computer can communicate with other devices in the same Local Area Network (LAN).

    sudo apt update
    sudo apt install net-tools
    

    To check the IP address of your computer, you can use the following command:

    ifconfig
    
    Output Example: namhost@server-host-839:~$ ifconfig
    eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.100.221 netmask 255.255.255.0 broadcast 192.168.100.255 inet6 fd00:db80::6 prefixlen 128 scopeid 0x0<global> inet6 2405:4802:80c2:cf00:b14:d108:2ab3:c023 prefixlen 64 scopeid 0x0<global> inet6 fd00:db80::c173:6ff3:2152:e89b prefixlen 64 scopeid 0x0<global> inet6 2405:4802:80c2:cf00:bf20:6e4:4350:e2a prefixlen 64 scopeid 0x0<global> inet6 fd00:db80::3d69:5558:97c4:e32c prefixlen 64 scopeid 0x0<global> inet6 fe80::8e42:2ec0:47fb:6a2d prefixlen 64 scopeid 0x20<link> inet6 2405:4802:80c2:cf00::6 prefixlen 128 scopeid 0x0<global> ether 10:e7:c6:7e:e6:0a txqueuelen 1000 (Ethernet) RX packets 383751 bytes 114963673 (114.9 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 597949 bytes 249543541 (249.5 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 3299 bytes 314563 (314.5 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3299 bytes 314563 (314.5 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
    

    My computer's IP address is 192.168.100.221. Everyone on my network can connect to this computer via port 80 (HTTP) http://192.168.100.221:80

3.2 Nginx Management

Basic management commands:

  • Start: sudo systemctl start nginx
  • Stop: sudo systemctl stop nginx
  • Restart: sudo systemctl restart nginx
  • Reload: sudo systemctl reload nginx
  • status: sudo systemctl status nginx

References:

After setting up the internal network environment, we will move forward and expand the accessibility from outside the LAN by opening ports and deploying a domain name. This will make your website easily accessible from anywhere in the world.

Thank you for taking the time to read this article! This is my first post, where I’ve gathered information from various sources. I hope the steps provided will help you easily deploy a website on Ubuntu VPS in a local environment. If you have any questions, suggestions, or need further assistance, feel free to leave a comment. Your feedback is invaluable and will help me improve future content!

Part 2: Expanding Connectivity: Configuring Ports and Deploying a Public Domain (Expected: 12/5/2024)

Bình luận

Bài viết tương tự

- vừa được xem lúc

Docker: Chưa biết gì đến biết dùng (Phần 1- Lịch sử)

1. Vì sao nên sử dụng. . .

0 0 104

- vừa được xem lúc

Docker: Chưa biết gì đến biết dùng (Phần 2 - Dockerfile)

1. Mở đầu.

0 0 67

- vừa được xem lúc

Cách Tạo Và Sử Dụng Bash Script Cơ Bản Trong Ubuntu

Bash scripting là một phần cực kỳ mạnh mẽ và hữu ích của phát triển và quản trị hệ thống. Lần đâu tiên làm việc với nó có thể gây cho bạn cảm giác sợ hải và phức tạp, mình hy vọng hướng dẫn này sẽ giúp có những hiểu biết cơ bản về bash script để không bị bở ngở khi làm việc với nó.

0 0 62

- vừa được xem lúc

Các command trên ubuntu (chiếm 80%) - phần 5

Hello 500 ae, sau 4 số trong seri này mình thấy có vẻ ae có hứng thú đọc chủ đề này ghê. Hi vọng những gì mình tìm hiểu được sẽ giúp ích được cho nhiều bạn hơn.

0 0 51

- vừa được xem lúc

Các command trên ubuntu (chiếm 80%) - phần 4

Sau một kì nghỉ tết trong thời buổi đại dịch vừa qua. Không còn những buổi dong chơi đi chúc tết nữa. Ở nhà ra số tiếp theo cho anh em đây. Dưới đây sẽ là 2 command được sử dụng nhiều nhất khi sử dụng file.

0 0 52

- vừa được xem lúc

Tài khoản người sử dụng và phân quyền truy cập tệp trên Ubuntu (P1)

Hôm nay, mình sẽ giới thiệu cho mọi người về Tài khoản người sử dụng (NSD) và phân quyền truy cập trên Ubuntu. Bài viết này được chia thành hai phần: phần một nói về tài khoản người sử dụng và phần hai nói về quyền truy cập trên Ubuntu.

0 0 43