Hi, I'm trying to set up a simple app, but unfortunately, it should run as old CGI script under Apache on Linux. The CGI script is reachable via http://server/appdir/script.cgi. I have set appdir/.htaccess like this: RewriteEngine On RewriteRule ^(.*)$ script.cgi The RewriteRule should be probably something like this: RewriteRule ^(.*)$ script.cgi?$1 The script calls Dancer app via Plack, that part works. Dancer renders templates just fine. The only problem I have is that the request->{path} variable is allways set to "/appdir/script.cgi" so my routes don't work. Can you please point me to correct settings to be able to make the routes work? The routes looking like this: get '/apdir/script.cgi?/path/:param' => sub { ... } would be ok. Even better would be if there was some way to allways strip the beginning of the path "/apdir/script.cgi?" so I would be able to write just the interresting part "/path/:param". Please assume that I am unable to run the application under FCGI or mod_perl. The Dancer's http server works but I need to make it work on our server... so... as plain CGI. Thank you. ico
Hi, Le mercredi 10 mars 2010 à 14:49 +0100, icovnik a écrit :
Hi,
I'm trying to set up a simple app, but unfortunately, it should run as old CGI script under Apache on Linux. The CGI script is reachable via http://server/appdir/script.cgi. I have set appdir/.htaccess like this:
RewriteEngine On RewriteRule ^(.*)$ script.cgi
The RewriteRule should be probably something like this:
RewriteRule ^(.*)$ script.cgi?$1
Not really, the rewrite rule should not path the path_info as a QUERY_STRING.
[...] Please assume that I am unable to run the application under FCGI or mod_perl. The Dancer's http server works but I need to make it work on our server... so... as plain CGI.
What you want to deploy is supported by Dancer with Plack, that works, and I'm going to give you a working example (which will then be added to Dancer::Deployment). This is how I deploy my test applications: I have a Virtualhost that matches *:80 which provides a bucnh of Dancer apps served within their own directories. This way I can access "AppFoo" with http://localhost/AppFoo/ (If understand you well, this is what you want). The following example provides /App1/ served by CGI and /App2/ served by FastCGI. Here is all that you need to get this working: <VirtualHost *:80> ServerName localhost # This is the root directory of all the apps DocumentRoot "/PATH/TO/YOUR/ROOTDIR" RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f <Directory "/PATH/TO/YOUR/ROOTDIR"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all AddHandler cgi-script .cgi AddHandler fastcgi-script .fcgi </Directory> RewriteRule /App1(.*)$ /App1/public/dispatch.cgi$1 [QSA,L] RewriteRule /App2(.*)$ /App2/public/dispatch.fcgi$1 [QSA,L] </VirtualHost> Please note that the RewriteRule does not use a question mark, the rewritten path should look (internally) like the following: /App1/foo/bar => /App1/public/dispatch.cgi/foo/bar request->path will then be - as you can expect - "/foo/bar" This works perfectly well on my box, it should work on yours ;) Good luck. -- Alexis Sukrieh
On Thu, Mar 11, 2010 at 9:29 AM, Alexis Sukrieh <sukria@sukria.net> wrote: [ cut ]
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule /App1(.*)$ /App1/public/dispatch.cgi$1 [QSA,L] RewriteRule /App2(.*)$ /App2/public/dispatch.fcgi$1 [QSA,L]
[cut]
This works perfectly well on my box, it should work on yours ;)
Yes perfect! That's the thing I wanted. Thank you. Just one more thing (probably more about Apache than about Dancer). Currently the URI http://server/App1/public/dispatch.cgi/foo/bar is catched by script /App1/public/dispatch.cgi. In dispatch.cgi it is matched by rule get '/foo/:par' => sub { ... }; I just wonder whether is it possible to get rid of that "dispatch.cgi" part in URI? To make the same functionality but with URIs like this: http://server/App1/public/foo/bar e.g. to completely hide the script name from outside. Thank you. ico
Le jeudi 11 mars 2010 à 12:05 +0100, icovnik a écrit :
I just wonder whether is it possible to get rid of that "dispatch.cgi" part in URI? To make the same functionality but with URIs like this:
http://server/App1/public/foo/bar
e.g. to completely hide the script name from outside.
If you followed my example, it is the case, I access my app the following: http://server/App1/foo/bar The rewrite rule does hide the dispatch.cgi part, it's done behind the scene.
On Thu, Mar 11, 2010 at 12:41 PM, Alexis Sukrieh <sukria@sukria.net> wrote:
Le jeudi 11 mars 2010 à 12:05 +0100, icovnik a écrit :
I just wonder whether is it possible to get rid of that "dispatch.cgi" part in URI? To make the same functionality but with URIs like this:
http://server/App1/public/foo/bar
e.g. to completely hide the script name from outside.
If you followed my example, it is the case, I access my app the following:
The rewrite rule does hide the dispatch.cgi part, it's done behind the scene.
Well... Yes and no :) If those Rewrite(Engine|Cond|Rule) settings are written in httpd.conf then everything works as you wrote - and that is EXACTLY what I wanted. But if the settings are in .htaccess file in /App1 then it behaves a bit differently, there should be the dispatch.cgi in URI as I wrote (becouse I was setting it in .htaccess as other settings). Just moving it to httpd.conf solved the problem. (So there is only a note for me to look at the differencies in apache docs) So again thank you for your help. ico
On Thu, Mar 11, 2010 at 5:05 AM, icovnik <icovnik@gmail.com> wrote:
On Thu, Mar 11, 2010 at 9:29 AM, Alexis Sukrieh <sukria@sukria.net> wrote: [ cut ]
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule /App1(.*)$ /App1/public/dispatch.cgi$1 [QSA,L] RewriteRule /App2(.*)$ /App2/public/dispatch.fcgi$1 [QSA,L] [cut] This works perfectly well on my box, it should work on yours ;)
Yes perfect! That's the thing I wanted. Thank you.
Just one more thing (probably more about Apache than about Dancer). Currently the URI
http://server/App1/public/dispatch.cgi/foo/bar
is catched by script /App1/public/dispatch.cgi. In dispatch.cgi it is matched by rule
get '/foo/:par' => sub { ... };
I just wonder whether is it possible to get rid of that "dispatch.cgi" part in URI? To make the same functionality but with URIs like this:
http://server/App1/public/foo/bar
e.g. to completely hide the script name from outside.
That is exactly what the RewriteRule is doing...
RewriteRule /App1(.*)$ /App1/public/dispatch.cgi$1 [QSA,L]
In english, it is saying, "if the path in the browser looks like a 'slash' followed by 'App1' possibly followed by other text (note, there is no 'dispatch.cgi' in the path in the browser', take all of the other text and stick it in '$1', then pretend the following path was requested - a 'slash' followed by 'App1/public/dispatch.cgi' followed by everything that was stuffed away in '$1'". So, I request '/App1/icovnik', and the server processes the command '/App1/public/dispatch.cgi/icovnik' which is taken by Dancer and broken into params->{:p} that you can now use in your query.
Thank you.
ico _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
-- Puneet Kishor http://www.punkish.org Carbon Model http://carbonmodel.org Charter Member, Open Source Geospatial Foundation http://www.osgeo.org Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor Nelson Institute, UW-Madison http://www.nelson.wisc.edu ----------------------------------------------------------------------- Assertions are politics; backing up assertions with evidence is science =======================================================================
participants (3)
-
Alexis Sukrieh -
icovnik -
P Kishor