1

I am trying to redirect services running on localhost under various ports to a sub-path on a single port. For example http://127.0.0.100:5687/ to http://127.0.0.1/app/.

The issue I am having is that only the first Virtual Host block works. If I swap the 2 hosts only topmost/first host work. All other hosts return Not Found error.

Here are the apache directives in question:

<VirtualHost *:80>
  ServerName app1.example.com
  #ServerAlias app1
  ProxyRequests Off
  ProxyPass /app1 http://127.0.0.1:6687/
  ProxyPassReverse /app1 http://127.0.0.1:6687/
</VirtualHost>

<VirtualHost *:80>
  ServerName app2.example.com
  #ServerAlias app2
  ProxyRequests Off
  ProxyPass /app2 http://127.0.0.1:7687/
  ProxyPassReverse /app2 http://127.0.0.1:7687/
</VirtualHost>

What am I not seeing here? Why does only the first Virtual Host work?

1

None of your VirtualHost blocks matches 127.0.0.1, so Apache takes the first block it finds.

Your virtualhosts are distinguished by the ServerName. If you want to reach both /app1 and /app2 with 127.0.0.1 you have to place both ProxyPass directives in the same VirtualHost block.

<VirtualHost *:80>
  ServerName app1.example.com
  ServerAlias app2.example.com
  ProxyRequests Off
  ProxyPass /app1 http://127.0.0.1:6687/
  ProxyPassReverse /app1 http://127.0.0.1:6687/
  ProxyPass /app2 http://127.0.0.1:7687/
  ProxyPassReverse /app2 http://127.0.0.1:7687/
</VirtualHost>

Or just use the ServerName instead in your http requests.

http://app1.example.com/app1/
http://app2.example.com/app2/

The /app* is redundant anyway, i'd just drop it and use ProxyPass / http://... with two VirtualHosts.

4
  • Could you elaborate on the second option? An example maybe? – DominicM Jun 21 '17 at 10:40
  • The second option is your current configuration. – Gerald Schneider Jun 21 '17 at 10:41
  • Ok, but how would that work locally accessed from lets say 192.168.0.100/app1? To clarify I want all of the following to point to a certain local app: app1/ (will modify /etc/hosts on client), http://[ip]/app1 (local network only) and app1.example.com (DNS will be configured). – DominicM Jun 21 '17 at 10:55
  • The first option doesn't work either, same result as before, only the first ProxyPass path works while the second returns 404. – DominicM Jun 21 '17 at 14:57

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.