Question

My manifest.appcache file is located at http://example.com/manifest.appcache however NGINX is looking for this file at /usr/share/nginx/html/manifest.appcache

I even added the following in my example.conf file:

 location /manifest.appcache {
   try_files $uri  /home/sushi/www/example/manifest.appcache;
 }

And my root is set as

root /home/sushi/www/example/;

What am I doing wrong?

Was it helpful?

Solution

Your nginx config looks fine if the server_name is exactly what you are using then I don't know exactly what's wrong, but let me tidy up your config, might help

For redirection I prefer to use a separate server to do the redirection instead of using an if condition

server {
    listen 80;
    server_name www.example.com;
    return 301 example.com$request_uri;
}

No need to re-declare the root and the index. specifying them once in the server block level is enough.

server {
    listen 80;
    server_name example.com;
    root /home/sushi/www/example/;
    access_log /home/sushi/www/example/logs/access.log;
    error_log /home/sushi/www/example/logs/error.log;
    index index.html index.htm;
    location / {
       try_files $uri $uri/ =404;
    }
}

Since your manifest.appcache is exactly where $uri would look then you don't need to explicitly mention it, The issue is that nginx won't match the server block.

Another random idea is that maybe nginx doesn't know that the server exists, cause you didn't restart nginx after creating a server.. did you try that ?

EDIT: The block inside the nginx.conf should be moved here inside the example.conf file

server {
    listen 80;
    server_name example.com;
    root /home/sushi/www/example/;
    access_log /home/sushi/www/example/logs/access.log;
    error_log /home/sushi/www/example/logs/error.log;
    index index.html index.htm;
    location / {
       try_files $uri $uri/ =404;
    }
    location ~* \.(?:manifest|appcache|html?|xml|json)$ {
        expires -1;
        access_log logs/static.log;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top