# (Re)Starting Devops

A while back, I had started my DevOps journey with great enthusiasm. But like many of us, life threw in other commitments, and I had to pause that path midway.

Fast forward to today — I’m finally restarting, and the excitement feels fresh again. This time, I’m more determined to be consistent and share my learnings along the way. Today marked **Day 2** of my journey, and it was quite an insightful one.  
  

## Learning About EC2

I began the day by diving deeper into **Amazon EC2 (Elastic Compute Cloud)**.

EC2 is essentially a virtual server in the cloud where you can host and run your applications. What stood out to me:

* You get full control of the server.
    
* You can choose your OS (I went with Ubuntu).
    
* It scales based on demand.
    
* And yes, it’s **pay-as-you-go**, which makes it beginner-friendly.
    

## Deploying a Next.js App on EC2

Next up was deployment. I wanted to get a simple Next.js app running on my instance. Here’s what I did:

1. **SSH into the EC2 instance**
    
    ```bash
    ssh -i "my-key.pem" ubuntu@<ec2-public-ip>
    ```
    
2. **Installed Node using NVM**  
    I didn’t want to mess with versions, so NVM made life easier.
    
    ```bash
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
    source ~/.bashrc
    nvm install 18
    ```
    
3. **Pulled in my Next.js project**
    
    ```bash
    git clone <your-repo-url>
    cd project
    npm install
    npm run build
    ```
    
4. **Kept it running with PM2**
    
    ```bash
    npm install -g pm2
    pm2 start npm --name "next-app" -- run start
    pm2 save
    pm2 startup
    ```
    
    At this point, my app was running on port `3000` inside the server. But of course, no one’s going to type `<ip>:3000` forever. That’s where Nginx came in.
    

## Setting Up Nginx Reverse Proxy

I installed Nginx and used it as a reverse proxy so that my app runs directly on port 80 (normal HTTP).

1. **Installed Nginx**
    
    ```bash
    sudo apt update
    sudo apt install nginx
    ```
    
2. **Configured reverse proxy**
    
    Edited the config:
    
    ```bash
    server {
        listen 80;
        server_name <your-ec2-ip-or-domain>;
    
        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;
        }
    }
    ```
    
3. **Restarted Nginx**
    
    ```bash
    sudo systemctl restart nginx
    ```
    
    Boom 💥 — app was live on EC2, no port nonsense.
    

## My Takeaways from Day 2

* EC2 is simple to get started with, but powerful enough to host almost anything.
    
* NVM saved me from Node version hell.
    
* PM2 is a lifesaver — no need to keep a terminal open to run my app.
    
* Nginx felt magical once the reverse proxy worked.
