Centos – Apache reverse proxy to nodejs server on CentOS 7.7 (WHM)

apache-2.4centosnode.jsreverse-proxy

I'm trying to setup an apache reverse proxy when accessing mysite.com to 127.0.0.1:3001, by setting up a virtual host in the WHM > Apache Configuration > Include Editor > Post VirtualHost Include (all versions).

I have a subdomain api.mysite.com (php) which is working and for front mysite.com I want to use a nodejs app that's running on server on localhost:3001.

This is what I have:

<VirtualHost *:80>
    ServerName mysite.com
    ServerAlias www.mysite.com

    ProxyRequests Off
    <Proxy *>
       Require all granted
    </Proxy>

   ProxyPass / http://127.0.0.1:3001/
   ProxyPassReverse / http://127.0.0.1:3001/
</VirtualHost>

It only works for front when I remove virtual host and use only this part, but then it uses reverse proxy for all, even the api.mysite.com.

ProxyRequests Off
<Proxy *>
    Require all granted
</Proxy>

ProxyPass / http://127.0.0.1:3001/
ProxyPassReverse / http://127.0.0.1:3001/

Best Answer

After a chat with Piotr, he suggested to create a conf file in the /etc/apache2/conf.d/userdata/std/2/user/mysite_com.conf and move the VirtualHost definition there, and it finally worked :)

Related Topic