🪟 Windows TippsMicrosoft Account Passkey not working [Fix](15.09.2026 um 14:36 Uhr)
🪟 Windows TippsDie neue Apple Watch mit Windows Recall?(15.09.2026 um 16:44 Uhr)
🪟 Windows TippsWindows 11 update breaks copy and paste in Microsoft Excel(15.09.2026 um 17:39 Uhr)
🪟 Windows ServerBSI warnt vor GitLab-Angriffswelle - IT-Administrator.de(15.09.2026 um 13:38 Uhr)
🪟 Windows TippsMicrosoft Account Passkey not working [Fix](15.09.2026 um 14:36 Uhr)
🪟 Windows TippsDie neue Apple Watch mit Windows Recall?(15.09.2026 um 16:44 Uhr)
🪟 Windows TippsWindows 11 update breaks copy and paste in Microsoft Excel(15.09.2026 um 17:39 Uhr)
🪟 Windows ServerBSI warnt vor GitLab-Angriffswelle - IT-Administrator.de(15.09.2026 um 13:38 Uhr)

🔧 Programmierung 🕛 vor 2 Jahren 9 Min Lesezeit
0

How to deploy a node server in EC2

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

Deploying a Node.js server on AWS EC2 allows you to leverage AWS's reliable infrastructure, scalability, and flexibility to host your application efficiently. This guide will take you step-by-step through setting up an EC2 instance, installing essential tools like Nginx and PM2, and securing your application with HTTPS using Let's Encrypt. By the end of this guide, you'll have a fully functioning Node.js server running on a secure EC2 environment, ready to handle production traffic.






Outline




  • Requirements

  • Setting Up EC2 Instance

  • Connecting to EC2 via SSH or Putty

  • Installing Necessary Packages and Tools

  • Setting Up PM2 for Node.js Application

  • Configuring Nginx as a Reverse Proxy

  • Accessing the Server Using Public IP

  • Understanding the Need for HTTPS

  • Setting Up Domain and SSL Certificates

  • Installing Certbot for SSL with Nginx

  • Mapping Domain to Public IP

  • Testing the Server and Final Checks






Requirements



Before starting, ensure you have the following:




  • An AWS account.

  • Basic knowledge of the Linux command line.

  • A registered domain name (for setting up HTTPS).


  • .



    After that it may ask for username which is usually by default - "ubuntu" if not set anything else.



    Next use the following command to switch to the root user:




    CODE
    sudo su






    Clone your Node.js application from GitHub or any other repository:




    CODE
    git clone <your-repo-url>
    cd <your-repo-directory>






    Switch to your prodution branch, pull the latest code and install node_modules.



    Once done return back to the main directory using cd..






    Setting Up ecosystem.config.js and Starting the Server with PM2



    PM2 is a popular process manager for Node.js that keeps your application running in the background and helps with load balancing and monitoring.



    Create ecosystem.config.js file in your project root:




    CODE
    touch ecosystem.config.js






    Open the file in a text editor and add your configuration:




    CODE
    nano ecosystem.config.js






    Add the configuration and save the file:




    CODE
    module.exports = {
    apps: [{
    name: "project_name",
    script: "npm start",
    cwd: "/home/ubuntu/repo",
    env: {
    "MONGO_URL": "mongodb+srv://<credentials>",
    "PORT": 3000,
    "NODE_ENV": "prod",
    }
    }]
    };






    Save and exit the editor (for nano, press Ctrl + X, then Y to confirm saving, and Enter to exit).






    Explanation of ecosystem.config.js File



    The ecosystem.config.js file is a configuration file for PM2, a process manager for Node.js applications. It defines how the application should be managed, including its environment variables, working directory, and startup script.






    Breakdown of the Configuration:




    • module.exports: Exports the configuration object so that PM2 can use it to manage the application.



    • apps: An array of application configurations. This allows PM2 to manage multiple applications using a single configuration file.





      • name: "project_name"
        The name of the application, as it will appear in PM2's process list. You can set this to your project name.


      • script: "npm start"
        The command to run the application. Here, it uses npm start to start the application, which typically runs the start script defined in your package.json.


      • cwd: "/home/ubuntu/repo"
        The "Current Working Directory" where PM2 will look for the application. This is the directory path where your Node.js application code (repository) is located.


      • env: An object defining environment variables that will be available to the application when it is running. These variables can be accessed in your Node.js code using process.env.








    Let's move next to starting our server:



    Start the Application Using PM2:




    CODE
    pm2 start ecosystem.config.js






    You can check the logs using:




    CODE
    pm2 logs









    Accessing the Server by Changing Security Rules Using Public IP



    Ensure your security group allows inbound traffic on port 3000 (or any port your server is running on). Access your server using:




    CODE
    http://<your-ec2-public-ip>:3000









    The Problem with HTTP Server and the Need for HTTPS



    HTTP is not secure for transmitting sensitive data. HTTPS, on the other hand, ensures that all data transmitted between the server and client is encrypted. Therefore, it's essential to secure your Node.js server with HTTPS, especially for production environments.






    Requirements for HTTPS: Domain and SSL



    To set up HTTPS, you need:




    • A domain name pointing to your EC2 public IP.

    • SSL certificate to encrypt the traffic.






    SSL Using Certbot and Setting Up Nginx



    Install Certbot on EC2:




    CODE
    sudo apt install certbot python3-certbot-nginx -y






    Run Certbot to Obtain SSL Certificate:




    CODE
    sudo certbot --nginx -d YOUR_DOMAIN






    Follow the prompts to complete the certificate installation. Certbot will automatically update your Nginx configuration to redirect HTTP traffic to HTTPS.



    You can check your updated nginx config. Go to this directory:




    CODE
    cd /etc/nginx/sites-available/






    Open the default file using nano, and it should look something like this:




    CODE
    server {
    listen 80;
    server_name YOUR_DOMAIN;

    # Redirect HTTP to HTTPS
    location / {
    return 301 https://$host$request_uri;
    }
    }

    server {
    listen 443 ssl;
    server_name YOUR_DOMAIN;

    ssl_certificate /etc/letsencrypt/live/YOUR_DOMAIN/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/YOUR_DOMAIN/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

    location / {
    proxy_pass http://127.0.0.1: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;
    }
    }






    After SSL setup it should reload Nginx server automatically but you can manually reload using:




    CODE
    nginx -s reload









    Domain Mapping to Public IP



    Ensure that your domain/subdomain is correctly mapped to your EC2 instance's public IP using A records in your domain DNS settings.






    Testing the Server and Finishing Up



    Visit https://YOUR_DOMAIN in your browser to verify the HTTPS setup. Your Node.js server should now be accessible securely via HTTPS.

    Vollständiger Original-Bericht
    Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
    ↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Microsoft Account Passkey not working [Fix]
1 Quelle
September-Patchday-Chaos: Microsoft flickt langsam sein eigenes Update
1 Quelle
Die neue Apple Watch mit Windows Recall?
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten How to deploy a node server in EC2

Thematisch verwandte Begriffe: deploy, node, server · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...