1

I am trying to open a static file with root function. Here is my NGiNX config:

location = /test {
            root    /var/53c74dc1c284ff0d63b019fd736f2c7965939e0452104120130821064016.png;
    }

I get this error in my browser:

404 Not Found

Also it does not seem to produce any errors in the NGiNX error logs.

I am using Ubuntu 12.

And I am using NGiNX version 1.2.7.

2 Answers 2

3

If you're trying to serve a single, specific file with the URI given for that location, use alias instead of root.

location = /test {
    default_type image/png;
    alias /var/53c74dc1c284ff0d63b019fd736f2c7965939e0452104120130821064016.png;
}

Loading http://www.example.com/test will then serve the named file.

4
  • It's forcing me to download the png image. Is there a way to view the image directly inside the browser? I tried types {} but it did not work.
    – jnbdz
    Sep 3, 2013 at 2:09
  • That's because it has no extension so nginx sends it as an application/octet-stream. Add in default_type image/png; inside this location to fix that. Sep 3, 2013 at 2:15
  • It does not work. It still forces a download.
    – jnbdz
    Sep 3, 2013 at 2:19
  • It now works. It was the caching.
    – jnbdz
    Sep 3, 2013 at 2:44
0

The root command is for directories, not files.

Try this, and move the PNG under your normal web root:

    location / {
            try_files test /53c74dc1c284ff0d63b019fd736f2c7965939e0452104120130821064016.png;
    }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .