Answer the question
In order to leave comments, you need to log in
How to set up ssl in node js?
I have a react spa application on ubuntu nginx - located in /var/www/bio-global.ru/admn
Config in 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
}
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()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question