2

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

3 Answers 3

2

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;
}
Sign up to request clarification or add additional context in comments.

5 Comments

No luck. One thing is that I am running nginx as www-data user while my app's permissions are for root:root - is that causing this? If I run nginx with 'root' things work fine. Are there any problems running nginx as root ?
It's a bad idea to run things as root unless they really have to be. Set the octal permissions for those static files to 644 (i.e. readable by other) so that www-data user can read them.
If you run things as root, any vulnerability in your app could destroy your server (since the exploit would run with root privileges)
True. Even if I set permission to 644 to /public folder for www-datda I get the same error. Not sure what to do.
Sorry, for files, set permissions to 644. For folders, set permissions to 755
0

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;
}

1 Comment

Still same issue after I disable assets from express.
0

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;
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.