Following up on my own email, I discovered a solution, and encountered another problem. See below, but note, the deployment documentation is still woefully inadequate -- On Jul 3, 2011, at 5:59 PM, Mr. Puneet Kishor wrote:
I have been using Dancer exclusively with Apache until now, but in a new environment, I want to experiment with Starman (or any other perl-based server) via Apache proxy. The machine in question is running Apache, and I am not inclined to tinker with that more than the minimum necessary.
I created an app "foo" in ~/Documents/www. I am able to run it like so
~/Documents/www/foo$ plackup -E deployment -s Starman --workers=10 -p 5001 -a bin/app.pl 2011/07/03-17:43:13 Starman::Server (type Net::Server::PreFork) starting! pid(3374) Binding to TCP port 5001 on host * Setting gid to "501 501 501 401 204 100 98 80 61 12 102 402"
Going to http://127.0.0.1:5001/ gives me my app "foo"
Now, I added the following in the apache conf file
---- ProxyRequests Off
<Proxy *> Order deny,allow Allow from all </Proxy>
ProxyPass /foo http://127.0.0.1:5001 ProxyPassReverse /foo http://127.0.0.1:5001 ----
and then, going to http://mycomputer.local/foo also returns my app "foo" correctly. Ok, then I added another app "bar" under ~/Documents/www (sibling to "foo"). Now, I am trying to run multiple apps as per the instructions at [http://search.cpan.org/~sukria/Dancer-1.3060/lib/Dancer/Deployment.pod] under the heading "Running multiple apps with Plack::Builder". I created the following web.psgi file in ~/bin
---- use Dancer ':syntax'; use Plack::Builder;
setting apphandler => 'PSGI';
my $app1 = sub { my $env = shift; setting appdir => '/Users/punkish/Documents/www/foo', setting appname => 'foo'; load_app "foo"; Dancer::Config->load; my $request = Dancer::Request->new( env => $env ); Dancer->dance( $request ); };
my $app2 = sub { my $env = shift; setting appdir => '/Users/punkish/Documents/www/bar', setting appname => 'bar'; load_app "bar"; Dancer::Config->load; my $request = Dancer::Request->new( env => $env ); Dancer->dance( $request ); };
builder { mount "/foo" => builder {$app1}; mount "/bar" => builder {$app2}; }; ----
Looking at [https://github.com/sukria/Dancer/commit/6c7ea733d5eac1d9ccfe39d70580ecf7d189...], I discovered that the documentation is wrong. Per the fix suggested at the above commit link, I changed the above to my $app1 = sub { my $env = shift; local $ENV{DANCER_APPDIR} = "/Users/punkish/Documents/www/foo"; setting appdir => "/Users/punkish/Documents/www/foo"; load_app "foo"; Dancer::App->set_running_app('foo'); Dancer::Config->load; my $request = Dancer::Request->new( env => $env ); Dancer->dance( $request ); };
and then I entered the following command:
~/bin$ plackup -E deployment -s Starman --workers=10 -p 5001 -a ~/bin/web.psgi
But, now I get "Not Found" error. So, besides generally seeking guidance for this, I have the following specific questions --
One, in "setting appdir => '/Users/punkish/Documents/www/foo'" what exactly is my appdir? Is '/Users/punkish/Documents/www/foo' correct?
The above appdir is correct.
Two, are both "foo" and "bar" going to be accessible at http://127.0.0.1:5001/? Do I just add the following lines to my httpd.conf
---- ProxyPass /foo http://127.0.0.1:5001 ProxyPassReverse /foo http://127.0.0.1:5001 ProxyPass /bar http://127.0.0.1:5001 ProxyPassReverse /bar http://127.0.0.1:5001 ----
I have to change the above to ProxyPass /foo http://127.0.0.1:5001/foo ProxyPassReverse /foo http://127.0.0.1:5001/foo ProxyPass /bar http://127.0.0.1:5001/bar ProxyPassReverse /bar http://127.0.0.1:5001/bar Now, I can access http://myserver.com/foo and http://myserver.com/bar and get my Dancer apps. There is a new problem -- seems like relative paths for files in the public folder are not calculated properly. If I request http://myserver.com/foo, I get the content, but I don't get any of the stylesheets in '/Users/punkish/Documents/www/foo/public/css' (they all result in 404). On the other hand, if I request http://myserver.com/foo/ (note the trailing slash) then the path to the stylesheets is resolved correctly. How do I fix this? Additionally, I still don't know the answer to the following two questions.
Three, how do I run plackup in the background? I want to run it, but be able to close the shell, and even logout and have it running.
Four, if I have a single web.psgi as above, one disadvantage is that if I tinker with any one app, and have to turn off or restart Starman, it will affect all the apps powered by Starman. Perhaps a better situation would be to have a separate Starman process for each app. What is the best practice here?
Puneet.