Deploying a Web Application Using NGINX on Alibaba Cloud

Deploying web app using NGINX on Alibaba Cloud

This article provides a comprehensive guide on deploying a web application using NGINX on Alibaba Cloud. It covers the necessary steps, from setting up your Alibaba Cloud account to configuring NGINX to serve your web application. By following this article, you can successfully host your application in a cloud environment, ensuring scalability and reliability.

Alibaba Cloud account to configuring NGINX

Prerequisites

Before you begin, ensure you have the following:

  1. An Alibaba Cloud account.
  2. Basic knowledge of Linux command line.
  3. A web application ready for deployment (e.g., HTML, CSS, JavaScript files).
  4. SSH client to connect to your cloud server.

Prerequisites

Step 1. Set Up an Alibaba Cloud ECS Instance

An Elastic Compute Service (ECS) instance is the foundation of your web application on Alibaba Cloud. Follow these steps to create and configure an ECS instance:

  1. Log In to the Alibaba Cloud Console
    Visit Alibaba Cloud and log in to your account. If you don’t have an account, sign up and complete the identity verification process.

  2. Create an ECS Instance

    • Navigate to ECS from the console dashboard.
    • Click Create Instance.
    • Select the Region and Zone closest to your target audience to minimize latency.
    • Choose an instance type that suits your application’s needs (e.g., ecs.c7.large for a standard web server).
    • Under the Image section, select a public image such as Ubuntu 22.04 or CentOS 8.
    • Configure Storage, ensuring enough disk space for your application and its dependencies.
    • Assign a public IP address for external access under the Networking section.
    • Set a strong password or upload your SSH key for secure access.
  3. Complete the Purchase

    • Review your configuration.
    • Click Create and wait for the ECS instance to initialize.

Step 2. Connect to Your ECS Instance

  1. Access via SSH

    • Open your terminal or an SSH client like PuTTY.
    • Use the command:
      ssh root@<Public_IP> -i <Path_to_SSH_Key>
      
      Replace <Public_IP> with your instance’s public IP address and <Path_to_SSH_Key> with your private key file path.
  2. Verify Connectivity

    • Upon login, you should see a prompt indicating successful access to the server.

Step 3. Install NGINX on the ECS Instance

  1. Update the System
    Run the following commands to update your package repository and system:

    sudo apt update && sudo apt upgrade -y   # For Ubuntu
    sudo yum update -y                      # For CentOS
    
  2. Install NGINX

    • On Ubuntu
      sudo apt install nginx -y
    • On CentOS
      sudo yum install nginx -y
  3. Start and Enable NGINX

    sudo systemctl start nginx
    sudo systemctl enable nginx
    
  4. Verify Installation
    Access your server’s public IP in a browser. If NGINX is correctly installed, you’ll see the default welcome page.

Step 4. Deploy Your Web Application

  1. Prepare Your Application Files
    Upload your application files to the server using tools like SCP, FileZilla, or directly through the Alibaba Cloud console file manager.

    Example (SCP)

    scp -i <Path_to_SSH_Key> /local/path/to/your/application root@<Public_IP>:/var/www/html/
  2. Configure NGINX

    • Edit the NGINX configuration file to point to your application’s directory:
      sudo nano /etc/nginx/sites-available/default # For Ubuntu 
      sudo nano /etc/nginx/nginx.conf # For CentOS
    • Add or update the server Block
      server {
          listen 80;
          server_name <Your_Domain> <Public_IP>;
      
          root /var/www/html;
          index index.html index.htm;
      
          location / {
              try_files $uri $uri/ =404;
          }
      }
      
  3. Restart NGINX
    Apply the changes by restarting the NGINX service:

    sudo systemctl restart nginx
  4. Verify Deployment
    Navigate to your public IP or domain in a browser. You should see your application’s homepage.

Step 5. Configure Security

  1. Set Up a Firewall Rule

    • Go to Security Groups in the Alibaba Cloud console.
    • Add a rule to allow HTTP (port 80) and HTTPS (port 443) traffic.
  2. Obtain a Domain Name and SSL Certificate

    • If using a domain name, map it to your server’s IP address using Alibaba Cloud’s DNS service.
    • Install SSL for HTTPS:
      sudo apt install certbot python3-certbot-nginx  # For Ubuntu
      sudo yum install certbot python2-certbot-nginx  # For CentOS
      sudo certbot --nginx -d <Your_Domain>
      
  3. Test SSL
    Use SSL testing tools to ensure your site is secure.

Step 6. Monitor and Optimize

  1. Enable Monitoring

    • Use CloudMonitor in Alibaba Cloud to track server performance and health metrics.
  2. Optimize for Traffic

    • Configure NGINX caching and load balancing if needed.
    • Scale your ECS instance or use Alibaba’s SLB (Server Load Balancer) for better traffic distribution.

Conclusion

Deploying a web application using NGINX on Alibaba Cloud is straightforward, with its updated console and extensive documentation. By following these steps, you can set up a secure, scalable, and high-performing web server for your application. Remember to update your server regularly, monitor its performance, and optimize based on traffic needs. Happy deploying!


Similar Articles
Ezmata Technologies Pvt Ltd
You manage your core business, while we manage your Infrastructure through ITaaS.