Не работает https на nginx
2023/07/17 21:18:08 [notice] 17472#19384: signal process started
2023/07/17 21:18:17 [notice] 18560#3444: signal process started
2023/07/17 21:31:42 [notice] 13628#3180: signal process started
2023/07/17 21:34:40 [notice] 8636#21436: signal process started
2023/07/17 22:01:02 [notice] 7140#17252: signal process started
2023/07/18 19:08:37 [emerg] 7660#8960: "location" directive is not allowed here in C:\nginx-1.25.1/conf/nginx.conf:29
Есть сервер на своём ПК на Windows 10 x64, работает через nginx+node.js. Решил себе установить сертификат через Certbot,вот такой вышел файл конфигурации nginx:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name auto8.pp.ua;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name auto8.pp.ua;
ssl_certificate C:/nginx-1.25.1/ssl/fullchain4.pem;
ssl_certificate_key C:/nginx-1.25.1/ssl/privkey4.pem;
location / {
proxy_pass http://192.168.0.199:3001;
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;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Вот настройки брандмауера, роутера,проверка портов перед запуском сервера
вот код index.js:
const express = require('express');
const mongoose = require('mongoose');
const { exec } = require('child_process');
const authRouter = require('./authRouter');
const PORT = process.env.PORT || 3001;
const cors = require('cors');
const app = express();
app.use(cors());
app.use(express.json());
app.use("/auth", authRouter);
app.use(express.static(__dirname));
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
next();
});
const start = async () => {
try {
await mongoose.connect('mongodb+srv://Start01:2587174728@cluster0.vnlcbha.mongodb.net/Automobiles?retryWrites=true&w=majority');
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`);
exec('start https://auto8.pp.ua/index.html', (error, stdout, stderr) => {
if (error) {
console.error(`Error opening browser: ${error}`);
}
});
});
} catch (e) {
console.log(e);
}
}
app.listen(3000, () => {
console.log('Сервер запущен на порту 3001');
});
start();
код auth.js:
const registrationForm = document.getElementById('registrationForm');
const loginForm = document.getElementById('loginForm');
registrationForm.addEventListener('submit', (e) => {
e.preventDefault();
const username = registrationForm.elements.username.value;
const password = registrationForm.elements.password.value;
fetch('https://auto8.pp.ua/auth/registration', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ username, password })
})
.then(response => response.json())
.then(data => {
console.log(data);
// Вывод сообщения об успешной регистрации или обработка ошибки
})
.catch(error => {
console.error(error);
// Обработка ошибки
});
});
loginForm.addEventListener('submit', (e) => {
e.preventDefault();
const username = loginForm.elements.username.value;
const password = loginForm.elements.password.value;
fetch('https://auto8.pp.ua/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ username, password })
})
.then(response => response.json())
.then(data => {
console.log(data);
// Вывод токена аутентификации или обработка ошибки
})
.catch(error => {
console.error(error);
// Обработка ошибки
});
});
вот какие файлы у меня есть по сертификату:
При http:// авторизация работает, но когда я провожу авторизацию через https:// то такие ошибки в консоли: «auth.js:32 POST https://auto8.pp.ua/auth/login net::ERR_SSL_PROTOCOL_ERROR (anonymous) @ auth.js:32 auth.js:45 TypeError: Failed to fetch at HTMLFormElement. (auth.js:32:5)». Вопрос в том: как мне настроить ssl сертификат через certbot на windows 10 чтобы сайт работал на https:// и что мне поменять в файле конфигурации, что я не так сделал? error.log