Serving DirectoryIndex via Dancer fails
My web site, [http://punkish.org] is Dancer powered (or, I should say, "proudly powered by Dancer"). However, from time to time, I create small, static, "micro-sites" under the same URI. For example, see [http://punkish.org/geoweb/index.html] or [http://punkish.org/opengov/index.html]. I serve these micro-sites from eponymous folders under /path/to/punkish/public/, so, for example, /path/to/punkish/geoweb and /path/to/punkish/opengov, etc. My httpd.conf is set to serve DirectoryIndex index.html and index.cgi. Yet, if I go to [http://punkish.org/geoweb] or [http://punkish.org/opengov], Dancer thinks I am trying to query for a page called geoweb or opengov -- I was under the impression that it would first see if by adding a trailing slash to the requested URI, it could located static directory. And, if I go to [http://punkish.org/geoweb/] or [http://punkish.org/opengov/], Dancer gives me a 404 error. I *have* to specify that I am looking for index.html in order to serve the static files. Is there a way to fix this? A fix, in my view, would be -- http://punkish.org/foo would be suffixed with a trailing slash and checked if a directory called foo exists. If it does, then the specified directory index would be served. If the directory doesn't exist, then Dancer would do its magic to determine how to serve the content request via foo. I am using Apache2 with vhosts. Puneet.
On Thu, 2011-03-17 at 08:49 -0500, Mr. Puneet Kishor wrote:
My httpd.conf is set to serve DirectoryIndex index.html and index.cgi.
httpd.conf is irrelevant to Dancer's behaviour.
Yet, if I go to [http://punkish.org/geoweb] or [http://punkish.org/opengov], Dancer thinks I am trying to query for a page called geoweb or opengov -- I was under the impression that it would first see if by adding a trailing slash to the requested URI, it could located static directory.
It'll simply look for a matching file and serve it if found. Dancer's static file serving is designed simply to serve up static files (images/CSS/Javascript etc) for a dynamic Dancer-powered web-app, not really to be a webserver to replace Apache/Nginx etc. In fact, for a busier site, I'd recommend configuring e.g. Nginx in front of the Dancer app to serve up the static files itself, and only pass through the requests which actually need to be handled by the Dancer app. I don't personally think that Dancer's static file serving should be extended to support DirectoryIndex etc; when you start to need that sort of thing, you should probably let a proper web server do it. Why not just configure Apache to serve those specific static sites itself, rather than involving Dancer in it? Cheers Dave P -- David Precious ("bigpresh") http://www.preshweb.co.uk/ "Programming is like sex. One mistake and you have to support it for the rest of your life". (Michael Sinz)
On Mar 17, 2011, at 9:31 AM, David Precious wrote:
On Thu, 2011-03-17 at 08:49 -0500, Mr. Puneet Kishor wrote:
My httpd.conf is set to serve DirectoryIndex index.html and index.cgi.
httpd.conf is irrelevant to Dancer's behaviour.
Yet, if I go to [http://punkish.org/geoweb] or [http://punkish.org/opengov], Dancer thinks I am trying to query for a page called geoweb or opengov -- I was under the impression that it would first see if by adding a trailing slash to the requested URI, it could located static directory.
It'll simply look for a matching file and serve it if found. Dancer's static file serving is designed simply to serve up static files (images/CSS/Javascript etc) for a dynamic Dancer-powered web-app, not really to be a webserver to replace Apache/Nginx etc. In fact, for a busier site, I'd recommend configuring e.g. Nginx in front of the Dancer app to serve up the static files itself, and only pass through the requests which actually need to be handled by the Dancer app.
I don't personally think that Dancer's static file serving should be extended to support DirectoryIndex etc; when you start to need that sort of thing, you should probably let a proper web server do it.
Why not just configure Apache to serve those specific static sites itself, rather than involving Dancer in it?
What you explain above makes sense, but not completely (to me). I thought I was doing just that -- having Dancer serve dynamic portion of my site, and letting Apache do its work for the static parts. All Dancer had to do was to determine whether a static file or directory was being requested; if yes, then let Apache do its job. In fact, if I understand correctly, the sequence is like so -- My .htaccess is RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule (.*) /dispatch.cgi/$1 [L] Apache receives a request for http://punkish.org(.*) if (.*) is not a directory or a filename, Apache hands the job to Dancer via dispatch.cgi So, if I understand correctly, Dancer shouldn't even have gotten involved when http://punkish.org/geoweb was requested, because Apache would have determined that I was requesting a directory. In other words, I am not asking for Dancer to be extended to replace Apache/Nginx, but to not get involved when a directory or a file are requested by name. With regards to Nginx, I am studying how to move to it, but there are many issues with it that are not clear to me. Baby steps for now. Many thanks, Puneet.
On Thu, 2011-03-17 at 09:47 -0500, Mr. Puneet Kishor wrote:
On Mar 17, 2011, at 9:31 AM, David Precious wrote:
On Thu, 2011-03-17 at 08:49 -0500, Mr. Puneet Kishor wrote:
My httpd.conf is set to serve DirectoryIndex index.html and index.cgi.
httpd.conf is irrelevant to Dancer's behaviour.
Yet, if I go to [http://punkish.org/geoweb] or [http://punkish.org/opengov], Dancer thinks I am trying to query for a page called geoweb or opengov -- I was under the impression that it would first see if by adding a trailing slash to the requested URI, it could located static directory.
It'll simply look for a matching file and serve it if found. Dancer's static file serving is designed simply to serve up static files (images/CSS/Javascript etc) for a dynamic Dancer-powered web-app, not really to be a webserver to replace Apache/Nginx etc. In fact, for a busier site, I'd recommend configuring e.g. Nginx in front of the Dancer app to serve up the static files itself, and only pass through the requests which actually need to be handled by the Dancer app.
I don't personally think that Dancer's static file serving should be extended to support DirectoryIndex etc; when you start to need that sort of thing, you should probably let a proper web server do it.
Why not just configure Apache to serve those specific static sites itself, rather than involving Dancer in it?
What you explain above makes sense, but not completely (to me). I thought I was doing just that -- having Dancer serve dynamic portion of my site, and letting Apache do its work for the static parts. All Dancer had to do was to determine whether a static file or directory was being requested; if yes, then let Apache do its job. In fact, if I understand correctly, the sequence is like so --
You've got it the wrong way round; Apache needs to determine whether to serve up a file itself, or pass the request off to your Dancer app. There's no way for Dancer, once it's been given a request, to identify that it should not be serving it and tell Apache to do it itself.
My .htaccess is
RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule (.*) /dispatch.cgi/$1 [L]
Apache receives a request for http://punkish.org(.*)
if (.*) is not a directory or a filename, Apache hands the job to Dancer via dispatch.cgi
So, if I understand correctly, Dancer shouldn't even have gotten involved when http://punkish.org/geoweb was requested, because Apache would have determined that I was requesting a directory.
What is your DocumentRoot set to? You'll want to configure the DocumentRoot to point to your public folder; given that, Apache *should* serve up files which exist in that directory directly, rather than passing them to Dancer.
In other words, I am not asking for Dancer to be extended to replace Apache/Nginx, but to not get involved when a directory or a file are requested by name.
Dancer doesn't get a choice in it; if the request has reached Dancer, that's your web server's configuration; Dancer has no way to say to Apache "No, I don't handle that, you do". Hope that helps a little? Cheers Dave P -- David Precious ("bigpresh") http://www.preshweb.co.uk/ "Programming is like sex. One mistake and you have to support it for the rest of your life". (Michael Sinz)
participants (2)
-
David Precious -
Mr. Puneet Kishor