I'm trying to use Apache and Node.JS at the same time but it is not working as expected.
// Apache
ProxyPreserveHost On
ProxyRequests Off
ServerName mydomain.com
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
And for my server.js
// Node
const express = require ('express');
const server = express();
server.get('/', function(req,res){
return res.send('The code works fine here');
});
server.get('/foo', function(req,res){
return res.send('Here => Cannot GET /foo');
});
server.get('/foo2', function(req,res){
return res.send('Here too => Cannot GET /foo2');
});
server.listen(3000, function() {
console.log('server is only working for "/" ')
});
mydomain.com works perfectly, but I cannot find a way to make all the other sub-domains mydomain.com/* to work. Can someone give me a light?
You can use Apache reverse proxy
Add this configuration to your apache conf.
ProxyPass "/nodeapp" "http:/localhost:8443"
You can access node application by http://www.example.com/nodeapp
A reverse proxy is a type of proxy server that retrieves resources on behalf of a client from the server. These resources are then returned to the client as if they originated from the web server itself.