I have two VMs running two webapps. We want to use example.com/foo for accessing VM1, and example.com/bar for accessing VM2.
For both VMs I need to call a cgi script for downloading. So I have ScriptAlias "/cgi-bin/" "/opt/example/lib/", and use www.example.com/cgi-bin/download.pl to download files.
When the VMs have its own domain, it works fine. But now we want to have the example.com/foo and example.com/bar setup, the download function on VM2 stopped working. As both VMs will call the script on VM1, and VM1 will return an error.
How shall I setup the Apache, so I can use example.com/foo/cgi-bin/download.pl to download the files on VM1 and use example.com/bar/cgi-bin/download.pl to download the files on VM2?
I have tried to set ScriptAlias "/foo/cgi-bin/" "/opt/example/lib/" but it didn't work.
Apache conf on VM1,
<VirtualHost *:80>
ServerName example.com
ScriptAlias "/cgi-bin/" "/opt/example/lib/"
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost On
ProxyPass /bar http://x.x.x.x/bar
ProxyPassReverse /bar http://x.x.x.x/bar
</VirtualHost>
Alias /foo /opt/example/script/fastcgi.pl/
<Directory "/opt/example/lib/">
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
AddHandler cgi-script .pl
SetHandler cgi-script
</Directory>
FastCgiServer /opt/example/script/fastcgi.pl -processes 3 -idle-timeout 3600
<Directory "/opt/example/script/">
Require all granted
</Directory>
Apache conf on VM2,
<VirtualHost *:80>
ServerName example2.com
ScriptAlias "/cgi-bin/" "/opt/example/lib/"
</VirtualHost>
Alias /bar /opt/example/script/fastcgi.pl/
<Directory "/opt/example/lib/">
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
AddHandler cgi-script .pl
SetHandler cgi-script
</Directory>
FastCgiServer /opt/example/script/fastcgi.pl -processes 3 -idle-timeout 3600
<Directory "/opt/example/script/">
Require all granted
</Directory>