Question

We have a perl web application that has been using plain CGI for a long time, and now we're trying to port over to Dancer 2 with something else (mod_perl, fastcgi, whathaveyou) so we can get more performance.

Here's the Apache setting we have right now (I know Starman is one highly recommended, but we'd like to stick to Apache as our web server)

<VirtualHost *>
...
        <Directory "/opt/alDente/versions/DanceApp/public">
                AllowOverride None
                Options +ExecCGI -MultiViews FollowSymLinks
                Order allow,deny 
                Allow from all
                AddHandler cgi-script .cgi
        </Directory>

        ScriptAliasMatch /dance/(.*) /opt/alDente/versions/DanceApp/public/dispatch.cgi/$1
        ProxyPreserveHost On
        ProxyPass /test http://localhost:3000/
        ProxyPassReverse /test http://localhost:3000/
        ...

The plain CGI method of deploying Dancer 2 (as seen above) works completely fine, even with multiple deployments under the same server. Problem: doing that gives us zero performance boost.

I also tried using the Simple web server that Dancer 2 comes with by default and having Apache point to it (as indicated above). It gets us great performance boost, is simple and easy to set up. Problem: we can't get multiple deployments set up with this setup, which is an absolute must for us. And also the internal URLs get screwed up with the proxying unless I change the /test to / (even if I have ProxyPreserveHost turned on), but that for obvious reasons won't work with multiple deployment.

I also spent the entire day yesterday trying to get mod_perl to work with this setup, but I've read that mod_perl also can't handle the multiple deployment on the same server and couldn't get it to work properly either.

I've also tried setting it up with fastcgi (using the dispatch.fcgi instead of dispatch.cgi that dancer 2 comes with), but that did not seem to give any performance boost.

What can I do to solve this issue? Using Apache and having something that can handle multiple deployments on the same server (due to budget issues, our server will have to host production, beta, and alpha environments) are musts for us.

Was it helpful?

Solution

It's perfectly possible to get multiple deployments behind a single Apache interface using mod_proxy.

Each app's settings need to be updated to use a unique port. For example, ports 3000, 4000, and 5000.

After that, you use mod_proxy with something similar to the below:

<VirtualHost *:80>
ProxyPass / http://localhost:5000/ retry=0 Keepalive=on
ProxyPassReverse / http://localhost:5000/
ProxyPreserveHost On
ServerName XXXXXXXXXXXXXXXXXXX
TimeOut 300
</VirtualHost>

By setting ServerName, you bind it to a specific subdomain.

You can use a Location directive instead if you wanted to bind it all to different urls:

<Location /production>
ProxyPass / http://localhost:5000/ retry=0 Keepalive=on
ProxyPassReverse / http://localhost:5000/
ProxyPreserveHost On
ServerName XXXXXXXXXXXXXXXXXXX
TimeOut 300
</Location>

However, if you're going to do this, Plack supports doing this at the App.psgi level, as described at https://metacpan.org/pod/Dancer::Deployment#In-case-you-have-issues-with-Template::Toolkit-on-Dotcloud (ignore the header and read, it is relevant).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top