Serving XHTML as HTML to MSIE browsers in NginX

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: Serving XHTML as HTML to MSIE browsers in NginX

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:

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: Re: Serving XHTML as HTML to MSIE browsers in NginX

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:

server-configuration/nginx/includes.conf at ad48f0b73ea8e2d33fc97bba60ddad2a4abca064 · ELLIOTTCABLE/server-configuration · GitHub

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 D.

Maxim D. Wrote:

the if: http://tr.im/ijbK?nginx (to quote,
if’s.
Try something like this:
types {};
default_type text/html;
}

Maxim D.

Posted at Nginx Forum:
Re: Serving XHTML as HTML to MSIE browsers in NginX

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

Posted at Nginx Forum: Re: Serving XHTML as HTML to MSIE browsers in NginX