Setting up Nginx to serve XML and XSLT

A few notes on some configuration you might want to do if you decided to enable XML and XSLT on your site for some reason.

So you've decided to take the plunge and make a site using XML and XSLT. First of all, my condolences. Second of all, assuming you've decided to use Nginx, there are a few configuration settings that you need to change1. For the purposes of these notes I'm going to assume that you can get Nginx installed and activated.

Once that's done, you'll want to edit your nginx.conf2.

Enabling gzip

The first thing to do is to enable gzip. It's a good idea to do this to minimize web traffic. You can do this by going to the HTTP stanza and adding the following lines:

gzip  on;

    gzip_disable "mise6";

    gzip_types text/plain text/css text/xml application/xml text/xsl application/xml+rss;

This tells Nginx to turn on gzip support, unless someone is browsing your site with Internet Explorer 6 for some reason3. We also have to specify the kinds of files we want to gzip. You might notice that XML is listed twice. That's because it's apparently given a MIME type of plain text and sometimes as an application. I just put both in there to cover my bases.

MIME Types

By default, Nginx doesn't know what an XSLT file is. You can tell it by editing the mime.types and adding a line to the 'types' stanza

text/xsl	xsl

Host config

This part is going to be a little bit different depending on if you use Virtual Hosts or not. If you don't know what Virtual Hosts are, then you're probably not using them.

You'll need to locate the line in either the main nginx.conf file or the appropriate virtual host config file that details what files nginx uses to serve up index pages4

You're looking for the line that says index and you want to add index.xml to the list. You can remove the other entries if you want to, but it's probably going to be handy later on if you don't do that.

Testing it out

To test that this is working, go to the root of the directory where your website files live, create a file called index.xml, put valid XML into it, then enter the URL of your website into your favorite web browser and see what you get.

If your XML is copied from the footnote below, then you will probably see a message complaining that the document doesn't have any style information (because it doesn't), and you'll just see a tag and the value in between the tags.

Congratulations! You've now cofigured Nginx to serve XML and XSLT. I'm sorry to have corrupted you.


  1. This is definitely not me just writing down what I did so I can recreate it the next time I need to set up a server or something. Nope. Definitely not.
  2. Its location will depend on what operating system you're using. Linux distributions usually put it in /etc/nginx and FreeBSD puts it in /usr/local/etc/nginx
  3. IE6 supports XML and XSLT, so on the off chance that someone has taken the time to get a version of Windows old enough to still run IE6 on the Internet and then browse to your site for some reason, we don't want them to be left out, I guess.
  4. And if you don't know what index pages are, you probably should do some research on the basics of website creation, and then come back to this article later.
  5. If you don't want to bother creating a whole slew of XML just for one page, the following snippet should be valid: <?xml version="1.0" encoding="UTF-8"?> <tag>Hello</tag>

Read more articles ยท Go back to the homepage