Change error page by file type?
Rt Ibmer
rtibmx at yahoo.com
Fri May 16 17:15:48 MSD 2008
Yes, however due to the complexity of our configuration (which includes many location blocks with several proxy_pass blocks inside), I am trying to avoid duplicating location blocks for this purpose.
I found something promising, however. According to the docs the the error_log directive is supported "if in location" as a context which it can be used in. Therefore I am thinking I can just add a group of if statements with regex checking inside of one location block and use the "if" block to set up the error_logs. I'll give this a try.
----- Original Message ----
From: Roxis <roxis at list.ru>
To: nginx at sysoev.ru
Sent: Friday, May 16, 2008 4:06:18 AM
Subject: Re: Change error page by file type?
On Friday 16 May 2008, Roxis wrote:
> On Thursday 15 May 2008, Rt Ibmer wrote:
> > Thanks. I am sorry I didn't mention it, but I need to do this from the
> > same location block which was my main reason in posting the question.
> > For instance I have a location block that takes care of serving multiple
> > file types and it needs to stay this way for other reasons. So within
> > that block I want to control the different error pages as I originally
> > described. Is this possible (perhaps with some sort of trick)? Thank
> > you!
> >
> > On Thursday 15 May 2008, Rt Ibmer wrote:
> > > If someone makes a request for a .js file from our server and no such
> > > file exists, I would like to return a different error page (actually an
> > > error.js page) in response. Yet if they request a .htm page I want to
> > > use a different error page (notfound.htm). Is this possible? If so can
> > > you please show an example configuration file snippet to do this? Thank
> > > you!
>
> the best way is to define two other locations with same configuration
>
> location /something/ {
> #config for location /something/
> }
>
- location ~ /something/.+\.js {
+ location ~ ^/something/.+\.js$ {
> #config for location /something/
> error_page 404 /errors/error.js;
> }
>
- location ~ /something/.+\.htm {
+ location ~ ^/something/.+\.htm$ {
> #config for location /something/
> error_page 404 /errors/notfound.htm;
> }
More information about the nginx
mailing list