<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ajeet Sahu</title>
    <description>The latest articles on DEV Community by Ajeet Sahu (@ajeet_sahu_bc00dce4aecf04).</description>
    <link>https://dev.to/ajeet_sahu_bc00dce4aecf04</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3632886%2F54f57df9-595b-4b53-bb92-2013fc74b0cb.jpg</url>
      <title>DEV Community: Ajeet Sahu</title>
      <link>https://dev.to/ajeet_sahu_bc00dce4aecf04</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ajeet_sahu_bc00dce4aecf04"/>
    <language>en</language>
    <item>
      <title>From Localhost to Live: A Practical Guide to Deploying a Next.js App on AWS EC2 (With Common Errors &amp; Fixes)</title>
      <dc:creator>Ajeet Sahu</dc:creator>
      <pubDate>Thu, 27 Nov 2025 14:03:04 +0000</pubDate>
      <link>https://dev.to/ajeet_sahu_bc00dce4aecf04/from-localhost-to-live-a-practical-guide-to-deploying-a-nextjs-app-on-aws-ec2-with-common-errors-3i5m</link>
      <guid>https://dev.to/ajeet_sahu_bc00dce4aecf04/from-localhost-to-live-a-practical-guide-to-deploying-a-nextjs-app-on-aws-ec2-with-common-errors-3i5m</guid>
      <description>&lt;p&gt;Deploying a Next.js application to an AWS EC2 instance is a common production pathway for modern web apps. However, while the deployment process looks straightforward, developers often encounter issues with SSH access, Linux permissions, missing libraries, Nginx conflicts, and more.&lt;/p&gt;

&lt;p&gt;This guide outlines a clean, step-by-step method to deploy a Next.js frontend to an Ubuntu EC2 instance—along with the most common errors you may encounter and how to resolve them.&lt;/p&gt;

&lt;p&gt;Infrastructure Overview&lt;/p&gt;

&lt;p&gt;Cloud Platform: AWS EC2 (Ubuntu)&lt;/p&gt;

&lt;p&gt;Frontend: Next.js (React)&lt;/p&gt;

&lt;p&gt;Runtime: Node.js (installed via NVM)&lt;/p&gt;

&lt;p&gt;Process Manager: PM2&lt;/p&gt;

&lt;p&gt;Reverse Proxy: Nginx&lt;/p&gt;

&lt;p&gt;Local Machine: Windows (with WSL Ubuntu terminal)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Connect to EC2 via SSH&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After launching the EC2 instance, the first task is to connect through SSH using your .pem key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common Error 1: “Unprotected Private Key File”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cause:&lt;br&gt;
The .pem file is stored on the Windows file system (/mnt/c/...).&lt;br&gt;
NTFS permissions do not map correctly to Linux, so chmod does not work.&lt;/p&gt;

&lt;p&gt;Fix: Move the key to the Linux file system and reapply permissions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cp /mnt/c/path/to/my-key.pem ~
cd ~
chmod 400 my-key.pem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Common Error 2: “Connection Timed Out”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cause:&lt;br&gt;
Inbound SSH traffic (port 22) is not allowed in the EC2 security group.&lt;/p&gt;

&lt;p&gt;Fix:&lt;/p&gt;

&lt;p&gt;Go to AWS Console → EC2 → Security Groups&lt;/p&gt;

&lt;p&gt;Edit Inbound Rules&lt;/p&gt;

&lt;p&gt;Add:&lt;/p&gt;

&lt;p&gt;Type: SSH&lt;/p&gt;

&lt;p&gt;Port: 22&lt;/p&gt;

&lt;p&gt;Source: Your IP (recommended)&lt;/p&gt;

&lt;p&gt;Then connect:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh -i "my-key.pem" ubuntu@&amp;lt;public-ip&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Install Node.js &amp;amp; Fix Missing Libraries&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Install Node.js using NVM (recommended for version management):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
source ~/.bashrc
nvm install node
nvm alias default node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Common Error 3: “libatomic.so.1: cannot open shared object file”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cause:&lt;br&gt;
Minimal Ubuntu images may not include a required library for newer Node.js versions.&lt;/p&gt;

&lt;p&gt;Fix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install libatomic1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Clone, Install, Build, and Run the App&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Clone your repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/your-username/your-repo.git
cd your-repo

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install dependencies and build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install
npm run build

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start the app using PM2 so it keeps running after you close SSH:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g pm2
pm2 start npm --name "next-frontend" -- start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check PM2 logs (optional):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pm2 logs next-frontend
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: Configure Nginx as a Reverse Proxy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Nginx will forward requests from port 80 → port 3000.&lt;/p&gt;

&lt;p&gt;Create a configuration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nano /etc/nginx/sites-available/next-frontend
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add this block:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
    listen 80;
    server_name serverName;

    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;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enable the site:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ln -s /etc/nginx/sites-available/next-frontend /etc/nginx/sites-enabled/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart Nginx:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl restart nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5: Fix “Welcome to Nginx” Showing Instead of Your App&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If visiting the server’s public IP still shows:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common Error 4 :Welcome to Nginx!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cause:&lt;br&gt;
The default Nginx config is still active and overriding your new configuration.&lt;/p&gt;

&lt;p&gt;Fix: Remove the default config:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo rm /etc/nginx/sites-enabled/default
sudo systemctl restart nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reload your browser — your Next.js app should now appear.&lt;/p&gt;

&lt;p&gt;Final Quick Commands (Reference Sheet)&lt;br&gt;
Purpose Command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SSH into server ssh -i key.pem ubuntu@public-ip
Fix key permissions chmod 400 key.pem
Install Node via NVM    nvm install node
Build Next.js app   npm run build
Start app with PM2  pm2 start npm --name "app" -- start
Restart Nginx   sudo systemctl restart nginx
View PM2 apps   pm2 list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Deploying a Next.js application on AWS EC2 involves working across Linux permissions, networking rules, process management, and web server configuration. The errors you encounter—SSH permission issues, timeouts, missing libraries, or Nginx conflicts—are common and straightforward to resolve once you understand their causes.&lt;/p&gt;

&lt;p&gt;With this guide, you should be able to deploy your app smoothly and troubleshoot the most frequent problems along the way.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>tutorial</category>
      <category>devops</category>
      <category>aws</category>
    </item>
  </channel>
</rss>
