0

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/
  • You need separate virtual host configurations for each domain, cf. Apache's documentation. – Piotr P. Karwasz Dec 9 '19 at 20:52
  • Thank you for your suggestion Piotr. But I found that I have to use the WHM interface for this, which will edit /etc/apache2/conf.d/includes/post_virtualhost_global.conf. So I can't edit the main conf to include other files because it will be overwritten by WHM. – vstruhar Dec 9 '19 at 21:18
  • Yes, but you can put two <VirtualHost> definitions in the same file. – Piotr P. Karwasz Dec 9 '19 at 21:21
  • I understand that I can have multiple VirtualHost definitions in the same file. But the main thing that confuses me, is why is this <VirtualHost *:80> definition ignored. And it only works when I set the proxy globally. – vstruhar Dec 9 '19 at 21:25
  • That probably means that WHM has defined another <VirtualHost> which overrides your config. Panel related questions are generally considered off topic here. – Piotr P. Karwasz Dec 9 '19 at 21:41
0

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 :)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.