Forum: NGINX Serving XHTML as HTML to MSIE browsers in NginX

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2974d09ac2541e892966b762aad84943?d=identicon&s=25 elliottcable (Guest)
on 2009-04-06 06:40
(Received via mailing list)
I'm trying to configure my server to serve XHTML files to MSIE browsers
as text/html.

Here's the three things I've tried; all of them yell at me about a
syntax error, so I can't launch my server:


location ~* \.(xhtml|xhtm) {
  if ($http_user_agent ~* MSIE) {
    types { }
    default_type text/html
  }
}



if ($http_user_agent ~* MSIE) {
  location ~* \.(xhtml|xhtm) {
    types { }
    default_type text/html
  }
}



includes.conf:
if ($http_user_agent ~* MSIE) {
  include /srv/conf/nginx/msie.conf;
}

msie.conf:
location ~* \.(xhtml|xhtm) {
  types { }
  default_type text/html
}


I've tried everything I can think of at this point. I can't find
documentation on what's allowed inside of an if() clause; it just keeps
throwing syntax errors at me.

I've also tried googling for other examples of the if() clause; all the
examples I could find only ever used it in this form:

if (-f …)


Is that the only thing the if() clause is useful for?

I've got some time sensitive content that *needs* to get online, and
moreover, be visible to MSIE users (that's a first for me). I don't have
the time to re-write my CMS to serve HTML to MSIE either; this should
really be done from the server side anyway. Any help would be much
appreciated!

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,839,839#msg-839
2974d09ac2541e892966b762aad84943?d=identicon&s=25 elliottcable (Guest)
on 2009-04-06 09:48
(Received via mailing list)
Okay, I talked to the nice people in the #NginX IRC room a bit (thanks
"merlincorey" and "Damn"!). From a more careful reading of the NginX
wiki's documentation, it appears that this should be legal:

http://github.com/elliottcable/server-configuratio...

Here's the reasoning. The wiki declares that the `types {}` declaration
is legal within a `location /…/ {}` declaration: http://tr.im/ijbz?nginx
- it also declares that the inside of an `if () {}` declaration should
inherit context from outside the `if`: http://tr.im/ijbK?nginx (to
quote, "Configuration inside directive if is inherited from the previous
level."). Therefore, having a `types` declaration inside an `if` inside
a `location` should be legal.

Unfortunately. with the configuration file as linked above, I can't
launch NginX; I get an "emergency" level error about syntax that kills
it on launch.

Is this a bug, then? Or is the documentation wrong? In either case, what
can I do to get my server fixed to (im)properly serve XHTML to MSIE?

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,839,842#msg-842
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2009-04-06 11:16
(Received via mailing list)
Hello!

On Mon, Apr 06, 2009 at 03:39:13AM -0400, elliottcable wrote:

> Okay, I talked to the nice people in the #NginX IRC room a bit (thanks "merlincorey" and 
"Damn"!). From a more careful reading of the NginX wiki's documentation, it appears that 
this should be legal:
>
> 
http://github.com/elliottcable/server-configuratio...
>
> Here's the reasoning. The wiki declares that the `types {}` declaration is legal within 
a `location /…/ {}` declaration: http://tr.im/ijbz?nginx - it also declares that the 
inside of an `if () {}` declaration should inherit context from outside the `if`: 
http://tr.im/ijbK?nginx (to quote, "Configuration inside directive if is inherited from 
the previous level."). Therefore, having a `types` declaration inside an `if` inside a 
`location` should be legal.

Directives allowed within if() blocks has context "if" or "if in
location" explicitly listed in their documentation.  Directives
types and default_type aren't allowed inside if's.

> Unfortunately. with the configuration file as linked above, I can't launch NginX; I get 
an "emergency" level error about syntax that kills it on launch.
>
> Is this a bug, then? Or is the documentation wrong? In either case, what can I do to get 
my server fixed to (im)properly serve XHTML to MSIE?

Try something like this:

    location ~ \.xhtml$ {
        error_page  405  = @html;

        if ($http_user_agent ~* MSIE) {
            return  405;
        }
    }

    location @html {
        types  {};
        default_type  text/html;
    }

Maxim Dounin
2974d09ac2541e892966b762aad84943?d=identicon&s=25 elliottcable (Guest)
on 2009-04-07 04:55
(Received via mailing list)
Maxim Dounin Wrote:
-------------------------------------------------------
> >
> the `if`: http://tr.im/ijbK?nginx (to quote,
> if's.
> Try something like this:
>         types  {};
>         default_type  text/html;
>     }
>
> Maxim Dounin
>
> >
> > Posted at Nginx Forum:
> http://forum.nginx.org/read.php?2,839,842#msg-842
> >
> >

That seems like … a horrid hack. Is there seriously no better way around
this?

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,839,846#msg-846
This topic is locked and can not be replied to.