Question

I testing out nginx but I bumped into a severe problem. Somehow the location tag doesn't catch my uri's. When the browser, or I manually try to access /favicon.ico on my localhost, it just throws an 404 error. The configuration looks like the following code:

server {
    listen       80;
    server_name  localhost;
    root         www;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

location / {
    index    index.html index.php;
}

    location = /favicon.ico {
    alias alias /assets/images/favicon.ico;
}

... and the error log looks like this:

2014/01/17 00:05:18 [error] 7408#10036: *82 CreateFile() "C:\Users\user\Webb\nginx/www/favicon.ico" failed (2: FormatMessage() error:(15105)), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost"

The log proves then that the location block was ignored, because the path nginx look for the file is not the one alias points to.

Was it helpful?

Solution

AFAIK nginx alias goes like this:

alias <the base path>

means that with it you tell the nginx the part to the left of your first "/" in the URI.

example. suppose I have my images in /var/www/html/images and my application refers to apic.jpg as http://app.com/pictures/apic.jpg , what I do then is this:

location ^/pictures {
  alias /var/www/html/images;
}

hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top