<div dir="ltr">It's probably easiest to have Apache serve the images, js, and css directly; put them all in central resources directory that Apache can serve. Here's a snippet from my httpd.conf file:<div><br></div><div><div><span style="white-space:pre"> </span>RewriteEngine On</div><div><br></div><div><span class="" style="white-space:pre"> </span># Dancer static file redirect<br></div><div><span class="" style="white-space:pre"> </span>RewriteRule ^/(css|images|js)/(.*) /web/public/$1/$2 [L]</div><div><span class="" style="white-space:pre"> </span>RewriteRule ^/(.*).html /web/public/$1.html [L]<br></div><div><br></div><div><span class="" style="white-space:pre"> </span># Plack server</div><div><span class="" style="white-space:pre"> </span># twiggy</div><div><span class="" style="white-space:pre"> </span>ProxyPass /async <a href="http://localhost:4010/">http://localhost:4010/</a></div><div><span class="" style="white-space:pre"> </span>ProxyPassReverse /async <a href="http://localhost:4010/">http://localhost:4010/</a></div><div><span class="" style="white-space:pre"> </span># starman</div><div><span class="" style="white-space:pre"> </span>ProxyPass / <a href="http://localhost:5678/">http://localhost:5678/</a></div></div><div><div><span class="" style="white-space:pre"> </span>ProxyPassReverse / <a href="http://localhost:5678/">http://localhost:5678/</a></div></div><div><br></div><div>All my static files (css, images, javascript, plus static html pages) are in the directory /web/public, and the first two rewrite rules parse incoming requests and serve those files directly. This filters out all URLs starting with /css/... /js/... /images/... and URLs ending with '.html'.</div><div><br></div><div>I have two Dancer-based apps running, using Starman and Twiggy as the servers, and proxied to different ports. Everything under /async is handled by Twiggy, and any requests that have not been caught by any of the previous filters are served by Starman.</div><div><br></div><div>The Dancer apps are launched by running "plackup -s Starman --workers=10 bin/app.psgi" or "plackup -s Twiggy bin/async-app.psgi".</div><div><br></div><div>You can serve CGI content using Apache (by setting up a ScriptAliased directory) or Plack; to use Plack, you can add something like this to your app.psgi file:</div><div><br></div><div><div>use Plack::Builder;</div><div><br></div><div>use AwesomeDancerApp;</div><div>my $new_app = sub {<br></div><div><div><span class="" style="white-space:pre"> </span>AwesomeDancerApp->to_app;</div><div>};</div></div><div><br></div><div>use Plack::App::CGIBin;</div><div>my $old_cgi = sub {</div><div><span class="" style="white-space:pre"> </span>Plack::App::CGIBin->new(root => "/old_code/" )->to_app; # this creates apps for all the CGIs in the directory 'old_code'</div><div>};</div></div><div><br></div><div><div>builder {</div><div><span class="" style="white-space:pre"> mount "/cgi-bin" => $old_cgi->();<br></span></div><div><span class="" style="white-space:pre"> </span>mount "/" => $pp->();<br></div><div>};<br></div></div><div><br></div><div>I hope that is helpful!</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 12 July 2016 at 14:07, janet davis <span dir="ltr"><<a href="mailto:oscarjwoofer@gmail.com" target="_blank">oscarjwoofer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Thank you for the quick response. <br><br>I think I've had a lightbulb moment, proxying through Apache works. The only problem is the uri_base doesn't point to the public directory in my application root it points to / so no css/js etc.<br><br></div>I have:<br>ProxyPass /app1 <a href="http://localhost:5000" target="_blank">http://localhost:5000</a><br>ProxyPassReverse /app1 <a href="http://localhost:5000" target="_blank">http://localhost:5000</a><br></div><div>And I can reach app1 on <a href="http://myserver.com/app1" target="_blank">myserver.com/app1</a><br></div><div><br></div>Is there anywhere in the config that I can specify the correct uri_base per app?<br><br></div>I will try using Plack Builder with some example apps. Are there any performance implications if I run a lot of Dancer apps in this way (15+) alongside my cgi scripts? I don't want to go down this route and then discover that I have issues with server resources.<br><br></div>Thanks again J.<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 12, 2016 at 9:21 PM, Chad Wallace <span dir="ltr"><<a href="mailto:cwallace@lodgingcompany.com" target="_blank">cwallace@lodgingcompany.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tue, 12 Jul 2016 19:55:31 +0100<br>
janet davis <<a href="mailto:oscarjwoofer@gmail.com" target="_blank">oscarjwoofer@gmail.com</a>> wrote:<br>
<br>
> Hi there,<br>
><br>
> I have a web server running Apache with a single vhost that serves a<br>
> lot of Perl cgi scripts from cgi-bin.<br>
><br>
> I've been trying out Dancer, which I really like, but I can't figure<br>
> out the best way to deploy apps in my Apache environment. I want to<br>
> keep my Apache cgi configuration to serve legacy scripts but I want<br>
> to start building new projects based on psgi in something like Dancer.<br>
><br>
> I want Apache to use www.myserver/cgi-bin/appname/<a href="http://script.pl" rel="noreferrer" target="_blank">script.pl</a> for old<br>
> code (which currently works) and www.myserver/app1 for newer Dancer<br>
> based apps. Please don't think I'm being lazy by asking, I have read<br>
> the documentation and looked at the example for deploying multiple<br>
> apps via fcgi but I am still confused as I have limited experience<br>
> with Apache - I am working on that. What's the best way to set this<br>
> up, bearing in mind that I may want to run say 10-15 Dancer apps from<br>
> my server alongside my cgi-scripts? Do I have to set up a vhost for<br>
> each app? I have Apache::Plack::Handler but I'm not sure whether I<br>
> should be using Plack::Builder to mount my apps (which is mentioned<br>
> in an older Dancer Cookbook, but not the current deployment guide.<br>
> Can someone help me get on the right track please?<br>
<br>
I'm not sure it matches what you currently have in mind, but what I<br>
would do is set up www.myserver/app1 with mod_proxy to a standalone<br>
Plack/Dancer process for the app. You would need something like this<br>
in your VirtualHost for each app:<br>
<br>
ProxyPass /app1 <a href="http://localhost:5000/app1" rel="noreferrer" target="_blank">http://localhost:5000/app1</a><br>
<br>
You'd also have to manage starting, stopping and reloading each of your<br>
apps on its own, with a dedicated port, like 5000 in the line above.<br>
<br>
If you wanted to combine your apps into one, you can do that with<br>
Plack::Builder in a single app.psgi script. Then you get the benefit<br>
of only having one script to start and stop, and one port. I currently<br>
do that with one of my apps to separate the AJAX-specific stuff, based<br>
on code I found in Dancer2::Cookbook[1]:<br>
<br>
#!/usr/bin/env perl<br>
<br>
use strict;<br>
use warnings;<br>
<br>
use FindBin;<br>
use lib "$FindBin::Bin/../lib";<br>
<br>
use Plack::Builder;<br>
use newtlc;<br>
use newtlc::API;<br>
<br>
builder {<br>
mount '/' => newtlc->to_app;<br>
mount '/api' => newtlc::API->to_app;<br>
};<br>
<br>
<br>
[1]<br>
<a href="https://metacpan.org/pod/distribution/Dancer2/lib/Dancer2/Cookbook.pod#App-specific-feature" rel="noreferrer" target="_blank">https://metacpan.org/pod/distribution/Dancer2/lib/Dancer2/Cookbook.pod#App-specific-feature</a><br>
<span><font color="#888888"><br>
<br>
--<br>
<br>
C. Chad Wallace, B.Sc.<br>
The Lodging Company<br>
<a href="http://www.lodgingcompany.com/" rel="noreferrer" target="_blank">http://www.lodgingcompany.com/</a><br>
OpenPGP Public Key ID: 0x262208A0<br>
<br>
_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
</font></span></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
<br></blockquote></div><br></div>