Setting Up an EC2 Server on AWS

Setting Up an EC2 Server on AWS

Step 1: Introduction to AWS

AWS, or Amazon Web Services, provides a vast array of cloud services. Here are some key features:

– Rent Servers: Flexibly rent virtual servers as needed.
– Manage Domains: Handle domain names and DNS settings.
– Upload Objects: Store various types of files including images, videos, and audio files.
– Autoscale Servers: Automatically adjust server capacity based on traffic.
– Create Kubernetes Clusters: Set up and manage Kubernetes clusters for containerized applications.

Step 2: Understanding EC2 Servers

AWS’s virtual machines are known as EC2 servers, which stands for Elastic Compute Cloud. The key features of EC2 include:

– Elastic: Easily scale the size of your machine up or down.
– Compute: Provides computing power as a machine.
– Dashboard Management: You can spin up new EC2 instances directly from the AWS dashboard.

Step 3: Creating a New EC2 Server

To create a new EC2 server, follow these steps:

  1. Click on Launch a New Instance
  2. Give a Name
  3. Select an Operating System (OS)
  4. Select Size
  5. Create a New Key Pair
  6. Select Instance Size Again
  7. Allow Traffic on HTTP/HTTPS

Step 4: SSH into the Server

Once your instance is running, you need to SSH into it. Here’s how:

  1. Give SSH Key Permissions:
    “`bash
    chmod 700 kirat-class.pem
    “`2. SSH into the Machine:
    “`bash
    ssh -i kirat-class.pem ubuntu@ec2-65-0-180-32.ap-south-1.compute.amazonaws.com
    “`3. Clone the Repository:
    “`bash
    git clone https://github.com/hkirat/sum-server
    “`If you encounter an error about internet access, follow this solution: https://www.tecmint.com/resolve-temporary-failure-in-name-resolution/.

    4. Install Node.js:
    Follow this DigitalOcean tutorial: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04.

    5. Install Dependencies:
    “`bash
    cd sum-server
    npm install
    “`

    6. Start the Backend:
    “`bash
    node index.js
    “`

Step 5: Installing the Repository

To install the repository, clone it using:

“`bash
git clone https://github.com/hkirat/sum-server
“`

Step 6: Accessing Your Server

After setting up, you can access your EC2 server using its IP or DNS. For example:

“`bash
http://your_domain:3000
“`

If you encounter issues accessing the server, you may need to configure the security group to open the necessary ports.

Step 7: Setting Up Nginx

Nginx is a powerful reverse proxy server. Here’s how to set it up:

  1. Install Nginx:
    “`bash
    sudo apt update
    sudo apt install nginx
    “`This should start the Nginx server on port 80.2. Configure Nginx as a Reverse Proxy:
    Edit the Nginx configuration file:
    “`bash
    sudo vi /etc/nginx/nginx.conf
    “`
    Add the following configuration:
    “`nginx
    events {
    # Event directives…
    }http {
    server {
    listen 80;
    server_name be1.100xdevs.com;

    location / {
    proxy_pass http://localhost:8080;
    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;
    }
    }
    }
    “`
    Reload Nginx to apply the changes:
    “`bash
    sudo nginx -s reload
    “`

    3. Start the Backend Server:
    “`bash
    node index.js
    “`

    4. Visit the Website:
    “`bash
    http://be1.100xdevs.com/
    “`

Step 8: Certificate Management

To secure your site with HTTPS, use Certbot. Follow the instructions on Certbot’s official site: https://certbot.eff.org/ to set up SSL certificates.

Conclusion

By following these steps, you can set up and manage an EC2 server on AWS, configure it with Nginx as a reverse proxy, and secure it with SSL certificates. AWS EC2 provides a robust and scalable environment for hosting your applications, and with tools like Nginx and Certbot, you can ensure your server is both accessible and secure. Happy hosting!

Leave a Reply

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