How to setup a node JS app as a subdirectory of a regular website without modifying DNS?

47 Views Asked by At

I'm working on a project with low resources and many restrictions I need to deploy an app as a subdirectory for an existing website, there are already some configured, and I have to maintain them while deploying my website.

With this kind of structure:

https://example.com - https://example.com/example

For the server, we are using CentOS 7, and it is configured with Apache.

There is already configured a virtualhost like this /etc/httpd/conf.d:

<VirtualHost *:80>
        ServerName example.com
        #Redirect / https://example.com/
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

The hosts file is also configured

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

I'm new to JavaScript and Node.js, so I tried this script:

import express from 'express';
import logger from 'morgan';

const port = process.env.PORT || 3000;

const app = express();
app.use(logger('dev'));

app.get('/', (req, res) => {
    res.send('Hello World');
});

app.listen(port, () => {
    console.log(`Server is running on port ${port}`);
});

I thought I could open other port, but I'm not sure how that could affect the SSL certificate. I have some issues modifying DNS, so my team preferred avoid to modificate it

In my first attempt, I was using Python, but I encountered too many issues with the server. I tried opening ports and was researching Name-Based Hosting and Virtual Hosting.

#################### UPDATE ####################

I'm trying to configure a reverse proxy like this

<VirtualHost *:80>
        ServerName example.com
        #Redirect / https://example.com/

        <Location /example>
              ProxyPass http://localhost:3000
              ProxyPassReverse http://localhost:3000
        </Location>

RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

0

There are 0 best solutions below