Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm setting up a simple virtual host to emulate a few specific responses that, in production, will come from a single URL. By way of an example, the production URL might look like this:

It actually returns text in .ini format. I've set up several test files in my webroot at /info/(legacy|new)/(daily|monthly)/device.htm that will test several different responses and I'd like to set up redirection so that I can redirect the same-ish url to the appropriate resource. The test URL might look something like this:

What I'd like to do is extract the appropriate values and serve up (in this example)


What Chrome, at least, is doing instead is attempting to download something called info.bin.

Here's my location block:

location ~ ^/(?<device>[^/]+)/(?<software>[^/]+)/(?<plan>[^/]+)/getdeviceinfo/info.bin$ {
  alias /opt/dev/hughesnet-modem-simulator/info/$software/$plan;
  try_files $uri $uri $device.htm

I've also tried setting the alias value to /opt/dev/hughesnet-modem-simulator/info/$software/$device.htm in lieu of try_files. I know I've just borked up the syntax, but I'm not sure where I've gone wrong.

Any insight would be much appreciated.



My current location block:

location ~ ^/(?<device>[^/]+)/(?<software>[^/]+)/(?<plan>[^/]+)/getdeviceinfo/info.bin$ {
  types {}
  default_type text/plain;
  alias /opt/dev/project-root/info/$software/$plan/$device.htm;
share|improve this question
up vote 1 down vote accepted

.bin is mapped by default to the MIME type application/octet-stream, which is why the browser tries to download it.

To fix this, override the MIME type mapping within your location block:

location /.... {
    types { }
    default_type text/plain;
    # the rest of your stuff
share|improve this answer
Somewhere in the last day or so, this has stopped working for me. Clearly I've done something, but I don't know what it was. Now, though, a file named info.bin is being downloaded (unexpected) and its content is that of $device.htm (expected). I've updated my question with the location block. Do you see anything that I borked up? Thanks. – Rob Wilkerson Sep 19 '12 at 12:19

Mixing alias-with-variables with try_files is probably the cause of your issue. Instead of using alias, just use root:

# Including the /s in the variables makes the try_files a little more efficient
location ~ ^(?<device>/[^/]+)(?<software>/[^/]+)(?<plan>/[^/]+)/getdeviceinfo/info.bin$ {
  # Set the root to the base of all the files
  root /opt/dev/hughesnet-modem-simulator/info;

  # construct the file path to append to the root
  try_files $software$plan$device.htm =404;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.