req.on("end" ...
app.post('/server', (req, res) => {
let mail = '';
req.on('data', chunk => {
mail += chunk
});
req.on('end', () => {
console.log(mail);
sendRuProgram(mail);
});
res.setHeader("Access-Control-Allow-Origin", "*"); /// Вот это
res.send('Отправили программу!');
});
location /server/ {
proxy_pass https://00.000.000.00:3000/server/;
}
return fetch(
'https://example.com:3000/server/',
{
method: 'POST',
mode: 'no-cors',
headers: {
'Content-Type': 'text/plain',
},
body: mail,
}
)
.then((response) => response.text());
const https = require('node:https');
const app = require('express')();
const fs = require('node:fs');
const host = '00.000.000.00';
const port = 3000;
const options = {
key: fs.readFileSync('/etc/letsencrypt/live/example.com/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/example.com/cert.pem'),
};
app.post('/', (req, res) => {
let mail = '';
req.on('data', chunk => {
mail += chunk
console.log(mail);
});
req.on('end', () => {
sendRuProgram(mail);
});
res.status(200).type('text/plain')
res.send('Отправили программу!');
})
https.createServer(
options,
app,
).listen(port, host, () => {
console.log(`Привет от сервера! https://${host}:${port}`);
});
const http = require('node:http');
const app = require('express')();
const fs = require('node:fs');
app.post('/', (req, res) => {
let mail = '';
req.on('data', chunk => {
mail += chunk
console.log(mail);
});
req.on('end', () => {
sendRuProgram(mail);
});
res.status(200).type('text/plain')
res.send('Отправили программу!');
})
http.createServer(
app
)
.listen(port, host, () => {
console.log(`Привет от сервера! https://${host}:${port}`);
});;
app.post('/', (req, res) => {});
resolver 45.146.164.83;
и добавил порт после ip в proxy_pass.nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:443, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:443, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
listen 3000 ssl;
Вообще, если удалить как я выше указал слово ssl и пути до ключа и сертификата, то сайт сразу на https уже открывается, просто при запросе на сервер по кнопке на сайте вылезает в консоли - ERR_SSL_PROTOCOL_ERROR; А с текущей конструкцией server сайт кидает ошибку 400. *211 SSL_do_handshake() failed
server {
listen 8080;
server_name example.com;
location / {
rewrite ^(.*)$ https://example.com$1 permanent;
}
}
server {
listen 3000 ssl;
server_name example.com;
root /var/www/example.com/;
index index.html;
ssl_certificate /etc/letsencrypt/live/example.com/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
location / {
proxy_pass http://00.000.000.00:8080;
}
location /server/ {
resolver 00.000.000.00;
proxy_pass https://00.000.000.00;
}
}
server {
listen 3000 ssl;
server_name exaple.com;
root /var/www/exaple.com/;
index index.html;
ssl_certificate /etc/letsencrypt/live/exaple.com/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/exaple.com/privkey.pem;
location /server/ {
resolver 00.000.000.00;
limit_except POST {
deny all;
}
proxy_pass http://00.000.000.00;
}
}