Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

724
Visualizações
NGINX net::ERR_CONNECTION_REFUSED with PM2 ReactJS Frontend and Express Backend in an AWS

I have running in an Amazon Web Server a ReactJS Frontend connecting to an Express APIREST. With PM2 to launch both processes and NGINX.

The problem comes when I try to log-in to the app in chrome, the frontend is okay but it refuses to connect to the APIREST. Error Image

These are the files I have:

APIREST .env

DB_CCT=my_db
DB_CCT_USER=user
DB_CCT_PASS=password
DB_CCT_HOST=127.0.0.1
NODE_ENV=development
PORT=8017
JWT_SECRET=jotauvedoblete

FRONTEND ReactJS .env

I also tried to add the public IP instead of localhost or 127.0.0.1 but doesn't work either, it shows the connection timed out.

REACT_APP_DB=http://localhost:8017/api/v1/

PM2 ecosystem.config.js

module.exports = {
  apps: [{
    name: 'CCT_REACT',
    cwd: 'cct-web-client/',
    script: 'npm',
 
    // Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
    args: 'run start:production',
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: '1G',
    env: {
      NODE_ENV: 'production',
      PORT: 5001
    },
    env_production: {
      NODE_ENV: 'production',
      PORT: 5001
    }
  },
  {
    name: 'CCT_API_REST',
    cwd: 'cct_api_rest/',
    script: 'npm',
 
    // Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
    args: 'run start',
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: '1G',
    env: {
      NODE_ENV: 'production',
      PORT: 8017
    },
    env_production: {
      NODE_ENV: 'production',
      PORT: 8017
    }
  }],
 
  deploy: {
    production: {
    }
  }
}

NGINX service

server {

        listen 80 default_server;
        listen [::]:80 default_server;

        root /home/ubuntu/CCT/cct-web-client/build;

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                try_files $uri/ /index.html?q=$uri&$args;
        }

}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If you are getting a connection refused, which means that the requests are getting blocked.

I see that you have specified PORT 8017 for your API App, check 2 things -

  1. Check in your AWS Security Groups of EC2 Inbound rules for PORT 8017 is open for all.
  2. Also try to Nginx restart once - `sudo systemctl restart Nginx.
  3. For your API, just start your API without pm2 & add a console.log in your route & middleware & make a POST request from POSTMAN to check if your app is working the right way.
about 4 years ago · Juan Pablo Isaza Relatório

0

Allow connect to port 80 on your aws and remove all other and use following nginx config. Also set api backend url in your frontend to your domain or ip on port 80.

server {

    listen 80 default_server;
    listen [::]:80 default_server;

    root /home/ubuntu/CCT/cct-web-client/build;

    index index.html index.htm index.nginx-debian.html;

    server_name _;

    # Frontend
    location / {
        try_files $uri /index.html;
    }

    # node api reverse proxy
    location /api/ {
        proxy_pass http://localhost:8017/;
    }

}

Also make sure to check first with any api client if you can consume your api without frontend. It should not be timedout.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda