@GNG999

Как настроить ssl в node js?

У меня на ubuntu nginx есть spa приложение реакт -находится в /var/www/bio-global.ru/admn
Конфиг в sites-available
upstream remoteApplicationServer {
    server 10.10.10.10;
}

upstream remoteAPIServer {
    server 20.20.20.20;
    server 20.20.20.21;
    server 20.20.20.22;
    server 20.20.20.23;
}


server {
    server_name www.bio-global.ru bio-global.ru;
    root /var/www/html;
    index index.html;
        location /remote { //мое реакт спа приложение
            alias /var/www/bio-global.ru/admn;
            try_files $uri $uri/ =404;
        }
          location /service {  //бэкэнд приложение node js 
            proxy_set_header   Host             $host:$server_port;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_pass http://localhost:5000;
        }
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/bio-global.ru/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/bio-global.ru/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

Я через letsencrypt сделал ссл сертификат.
У меня есть нод бэкэнд приложение -находится в /var/www/bio-global.ru/service (выше в конфиге его настройки есть )
оно запускается на 5000 порту
его index.js
require('dotenv').config()
const fs = require('fs');
const http = require('http');
const https = require('https');
const express = require('express')
const sequelize = require('./db')
const models = require('./models/models')
const cors = require('cors')
const fileUpload = require('express-fileupload')
const router = require('./routes/index')
const errorHandler = require('./middleware/ErrorHandlingMiddleware')
const path = require('path')

const PORT = process.env.PORT || 5000
//const privateKey = fs.readFileSync('/etc/letsencrypt/live/bio-global.ru/privkey.pem', 'utf8');
//const certificate = fs.readFileSync('/etc/letsencrypt/live/bio-global.ru/cert.pem', 'utf8');
//const ca = fs.readFileSync('/etc/letsencrypt/live/bio-global.ru/chain.pem', 'utf8');

/*const credentials = {
        key: privateKey,
        cert: certificate,
        ca: ca
}*/
//const httpServer = http.createServer(app);
//const httpsServer = https.createServer(credentials, app);
const app = express()
app.use(cors())
app.use(express.json())
app.use(express.static(path.resolve(__dirname, 'static')))
app.use(fileUpload({}))
app.use('/api', router)

// Обработка ошибок, последний Middleware
app.use(errorHandler)

const start = async () => {
    try {
        await sequelize.authenticate()
        await sequelize.sync()
        app.listen(PORT, () => console.log(`Server started on port ${PORT}`))
    } catch (e) {
        console.log(e)
    }
}
start()

с реакт приложения запросы на бэк приложение идут по урлу bio-global.ru:5000/api , но выходит ошибка blocked mixed content
я так понял надо в node js приложении настроить ssl ? в индекс файле раскомментировать строки ?
  • Вопрос задан
  • 178 просмотров
Пригласить эксперта
Ответы на вопрос 1
ky0
@ky0 Куратор тега Nginx
Миллиардер, филантроп, патологический лгун
То, что происходит в браузере, не должно ходить без шифрования на странные порты. У вас же есть в конфиге нормально настроенное проксирование /service, сделайте такое же для /api.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы