Report this

What is the reason for this report?

Problemas con express despues de installar el ssl de certbot. abre la pagina pero no conecta a express

Posted on November 12, 2019

Configuré mi droplet e instalé nginx exitosamente y me puedo conectar al puerto 3000 del frontend y por el puerto 3002 a mi base de datos a traves de express. mi problema es que al instalar el certificado ssl de certbot la pagina abre por https. pero no encuentro forma de conectarme al puerto de express y antes conectaba sin el certificado.

app.js de express de prueba

const express = require("express");
const bodyParser = require("body-parser"); // Se requiere bodyParser para convertir y decodificar json
const app = express();

const http = require('http');

const server = http.createServer(app)

//Protege express configurando varios encabezados http
const helmet = require("helmet");
app.use(helmet());

//Aqui se requiere definir las Rutas
const routerUser = require("./routes/controllers/datamaestra/usuarios");

//Esta configuración del cors hay que hacerla aquí antes de los demás módulos
const cors = require("cors");
app.use(cors());

// Node.js usará los middleware json
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// Levantar el servicio express
server.listen(3002, error => {
  if (error) return console.log(`Error: ${error}`);
  console.log(
    `El servidor Socket.io y express está corriendo en el puerto: ${server.address().port}`
  );
});

routerUser(app);

Archivo de nginx sin ssl

server{
listen 80 default_server;
server_name maasfino.com www.maasfino.com

server_name dev ipv6only=on;

root /usr/share/nginx/html;

index index.php index.html index.htm;
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;
    }
}

No se donde se configura el puerto 3002 de express para que funcione con ssl. asi funciona perfecto sin el certificado.

Agradecería el apoyo al respecto. disculpen. gracias



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hey,

You’ll need to add anther block for the secure connection and have it for port 443 as well and not only port 80 which is for http.

We have a tool which can help you to configure the Nginx configuration

https://www.digitalocean.com/community/tools/nginx

Hope that this helps!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.