Node.js:Nginx-won';不提供静态内容

Node.js:Nginx-won';不提供静态内容,node.js,nginx,Node.js,Nginx,我正在尝试通过node.js应用程序上的nginx提供静态内容。对于看似简单而明显的设置,我无法通过nginx路由静态内容。这一行: 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;

我正在尝试通过node.js应用程序上的nginx提供静态内容。对于看似简单而明显的设置,我无法通过nginx路由静态内容。这一行:

  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不提供任何静态内容(js、css、图像)——但删除这些内容后,我会看到显示静态内容。 在节点端,我使用express和jade

nginx.conf:

默认值:

尝试以下方法

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;
}
请尝试以下操作:

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


在我从express中禁用资产后仍然存在相同的问题。运气不好。一件事是,我以www数据用户的身份运行nginx,而我的应用程序的权限是root:root-这是造成这种情况的原因吗?如果我使用“root”运行nginx,一切都会正常工作。以root身份运行nginx有什么问题吗?以root身份运行东西是个坏主意,除非它们真的必须以root身份运行。将这些静态文件的八进制权限设置为644(即,其他用户可以读取),以便www数据用户可以读取它们。如果您以root用户身份运行,则应用程序中的任何漏洞都可能破坏您的服务器(因为此漏洞将以root权限运行)。即使我将www datda的权限设置为644 to/public folder,我也会收到相同的错误。不确定要做什么。抱歉,对于文件,请将权限设置为644。对于文件夹,将权限设置为755
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;
    }