具有反向代理设置的CGI(Apache)

时间:2017-02-20 10:00:15

标签: apache perl cgi reverse-proxy

我有两个运行两个webapps的VM。我们希望使用example.com/foo访问VM1,使用example.com/bar访问VM2。

对于两个虚拟机,我需要调用cgi脚本进行下载。所以我有 ScriptAlias“/ cgi-bin /”“/ opt / example / lib /”,并使用www.example.com/cgi-bin/download.pl下载文件。

当VM拥有自己的域时,它可以正常工作。但是现在我们想要设置example.com/foo和example.com/bar,VM2上的下载功能停止工作。由于两个VM都将在VM1上调用脚本,因此VM1将返回错误。

我如何设置Apache,所以我可以使用example.com/foo/cgi-bin/download.pl在VM1上下载文件并使用example.com/bar/cgi-bin/download.pl下载VM2上的文件?

我试图设置 ScriptAlias“/ foo / cgi-bin /”“/ opt / example / lib /”,但它不起作用。

VM1上的Apache conf,

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

0 个答案:

没有答案