I am using Cyberpanel with Ubuntu 22.04. I have created a website srv.example.com and inside its public_html I have installed an express server and the app.js file is the below:
const express = require('express');
const fs = require('fs');
const https = require('https');
const app = express();
const port = 3001;
const options = {
key: fs.readFileSync('/etc/letsencrypt/live/srv.example.com/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/srv.example.com/fullchain.pem')
};
app.get('/', (req, res) => {
res.send('Hello, World!');
});
https.createServer(options, app).listen(port, () => {
console.log(`Express server is running on https://localhost:${port}`);
});
In Vhosts conf I have added the below code
<VirtualHost *:443>
ServerName srv.example.com
DocumentRoot /home/srv.example.com/public_html
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/srv.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/srv.example.com/privkey.pem
ProxyPreserveHost On
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001/
ErrorLog /usr/local/lsws/logs/srv.example.com.error_log
CustomLog /usr/local/lsws/logs/srv.example.com.access_log combined
I have also created an A record in CLoudlfare pointing to my server IP
When I make a GET call from postman → https://{SERVER-IP}:3001 it works. It replies with “Hello, World!”
But when a make a GET call → https://srv.example.com I receive a 404 page.
Please help me understand what I am doing wrong. I am beginner in server related things.