running an Apache cgi via Dancer
I might have asked this question earlier, but in any case, here goes again. Hopefully one of knowledgable folks can guide me toward the right path. I have my Dancer app running behind an Apache2 proxy, so when the user goes to `http://server/app`, apache serves content retrieved from `http://127.0.0.1:port/` that is being served by Starman+Dancer. My application also serves maps via Apache+MapServer from `http://server/cgi-bin/mapserv`. In reality, I have not just `/app` but `/app1`, `/app2`, `/app3` and so on. In order to send `/app<n>` specific MapServer information to the cgi program, I have shell script wrappers called `app1`, `app2`, `app3` in my cgi-bin directory. Their content is like so ("app<n>.map" is a "mapfile" for app<n>. There is one for each app). #!/bin/sh MAPSERV="/path/to/punkish/cgi-bin/mapserv" MAPFILE="/path/to/app<n>.map" if [ "${REQUEST_METHOD}" = "GET" ]; then if [ -z "${QUERY_STRING}" ]; then QUERY_STRING="map=${MAPFILE}" else QUERY_STRING="map=${MAPFILE}&${QUERY_STRING}" fi exec ${MAPSERV} else echo "Sorry, I only understand GET requests." fi exit 1 With that background, I now have all my app-specific stuff in my Dancer directory, except this shell script that is in the apache cgi-bin directory. This makes management difficult, and I would like to move these files to the Dancer directory. Except, I haven't been able to figure out how to execute apache cgi-bin programs from Dancer. I tried the following in my app but I get a 502 Proxy Error. # http://server/app/ms get '/ms' => sub { my $MAPSERV = '/path/to/punkish/cgi-bin/mapserv'; my $MAPFILE = '/path/to/app.map'; my $params = params(); my $QUERY_STRING = ""; while (my ($k, $v) = each %$params) { $QUERY_STRING .= "$k=$v"; } $QUERY_STRING .= "&$MAPFILE"; exec("$MAPSERV $QUERY_STRING"); }; In other words, I want to take the /ms route and send it off to Apache to execute (via Apache's cgi interface) and return the content via Dancer. That sounds like I want to use Dancer as a proxy for Apache while Apache is already a proxy for Dancer, but actually, all I want is to store certain files under the Dancer app directory, but let Apache handle them instead of Dancer. Suggestions? -- Puneet Kishor
On Dec 7, 2011, at 3:34 AM, sawyer x wrote:
On Tue, Dec 6, 2011 at 10:38 PM, Puneet Kishor <punk.kish@gmail.com> wrote:
Suggestions?
Why?
You can wrap CGI apps as Plack apps and serve them using plack under a different URL.
My apologies as I have not been able to communicate my use case clearly. I need to use Apache+MapServer -- that is, access MapServer via Apache as a cgi program, not Perl's CGI.pm. The reason I need to use Apache+MapServer is because MapServer's cgi interface has been designed with Apache in mind, and there are additional related programs that work with Apache. For example, mod_mapcache is an Apache module that caches map tiles generated by MapServer. So, the basic requirement is that I need to send a request of the sort http://server/cgi-bin/app where cgi-bin is Apache's ScriptAlias directory. Now, since the mapping functionality is a part of the Dancer app, I need to keep track of two URIs... one that is Dancer-based (for example, http://server/app where everything that is /app is proxied to Starman+Dancer) and the other that is for Apache only such as http://server/cgi-bin/app This means I have to maintain app-specific bits-and-bobs in two places: one, inside the Dancer/app folder, and; two, inside the cgi-bin folder. And, that is what I am trying to get around. -- Puneet Kishor
participants (2)
-
Puneet Kishor -
sawyer x