1

Say I have basic PHP site installed at http://example.com. Then, at http://example.com/groovy, we have an express.js app running on Node.

I have the app running on the default express port of :3000. I would expect then to visit http://example.com/groovy:3000 and see the same webpage found at http://localhost/groovy:3000. However, this is not the case.

Instead I am only able to access the /groovy site by going to http://example.com:3000. This entirely disregards the subdirectory.

I anticipate part of the setting has to do with the Apache httpd.conf file. Since I don't know exactly, my best bets are guess and check (very inefficient).

Here is the current setup:

<VirtualHost *:80>
    Servername example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com
</VirtualHost>

^ This delivers the regular PHP site. Then going to /groovy should deliver the Node/express.js site.

Further, I have not found yet the proper way to not require a port number in the URL. I want to be able to go to http://example.com/groovy and be delivered the express.js content.

I tried setting some rewrite rules in the base URL .htaccess, like this

RewriteEngine On
RewriteRule groovy http://example.com:3000

But this hasn't worked out yet. Any other suggestions?

Naltroc
  • 989
  • 1
  • 14
  • 34
  • port number should always come after the domain name / ip address. `http://example.com/groovy:3000` is not even a valid thing for what you want. But you can create a virtual host that maps `/groovy` to your 3000 port using [`mod_proxy`](https://stackoverflow.com/questions/14259321/apache-node-js-mod-proxy-how-to-route-one-domain-to-3000-and-another-to-8). – Aᴍɪʀ Jan 01 '18 at 01:00

1 Answers1

0

You should use ProxyPass and ProxyPassReverse directive to pass the request to proxied server, express app.

<VirtualHost *:80>
    Servername example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com
    ProxyPass /groovy http://example.com:3000
    ProxyPassReverse /groovy http://example.com:3000
</VirtualHost>
Ben
  • 5,069
  • 4
  • 18
  • 26