Ved
Ved

Reputation: 3500

Node.js : Nginx won't serve static content

I am trying to server static content via nginx on my node.js app. For the seemingly simple and obvious setup, I am not able to route the static content via nginx. With this line :

  location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ {
                    access_log off;
                    expires max;
    }

nginx does not server any static content (js, css, images) - but on removing this I see that static contents are displayed. On Node side, I am using express and jade.

nginx.conf: https://gist.github.com/3331669

default: https://gist.github.com/3331674

Upvotes: 2

Views: 1492

Answers (3)

Matt
Matt

Reputation: 81

Try

location ~* .*\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ {
        access_log off;
        expires max;
        root /var/www/yoursitename/public;
    }

Upvotes: 0

matzahboy
matzahboy

Reputation: 3024

Try the following:

location ~  \.(jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ {
  access_log off;
  expires max;
}

Upvotes: 2

cobaco
cobaco

Reputation: 10556

Try the following

location ~*  .*\.(jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html?)$ {
  access_log off;
  expires max;
}

Upvotes: 0

Related Questions