如何直接使用NGINX为所有现有静态文件提供服务,但将其他请求代理给jetty?

如何直接使用NGINX为所有现有静态文件提供服务,但将其他请求代理给jetty?,nginx,proxy,Nginx,Proxy,我的问题类似于 不同的是,我的站点目录结构如下所示: /nginxRoot/test/js /nginxRoot/test/images /nginxRoot/test/html ........ 因此,站点根不是/nginxRoot/而是/nginxRoot/test/ 我想使用nginx来服务所有已放置在目录中的静态文件:js、images、html和代理jetty的其他请求,我尝试过: location ~ ^/test/(.*)\. (jpg|jp

我的问题类似于

不同的是,我的站点目录结构如下所示:

/nginxRoot/test/js        
/nginxRoot/test/images  
/nginxRoot/test/html
........       
因此,站点根不是/nginxRoot/而是/nginxRoot/test/

我想使用nginx来服务所有已放置在目录中的静态文件:js、images、html和代理jetty的其他请求,我尝试过:

location ~ ^/test/(.*)\.   (jpg|jpeg|gif|png|js|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$
{
    root  /ngixRoot/test;
}

 location ~ ^/test/(.*)$ {
    proxy_pass http://127.0.0.1:8080/$1$is_args$args;
    proxy_redirect off;
}
所有对jetty的请求都有效,但所有对静态文件的请求都无效,我怀疑它们是否也被转发到jetty,这是真的吗?如何解决这个问题

更新 遵循@Alexey.Ten的建议

我试过了

location ~ ^/test/$ {       
   try_files $uri $uri/ @jetty
} 

location @jetty {
    internal;
    add_header X-Local true;
    add_header X-Cache $upstream_cache_status;

    proxy_pass              http://$http_host:8080$uri$is_args$args;
    proxy_cache             one;
    proxy_cache_key         backend$request_uri;
    proxy_cache_valid       200  1h;
    proxy_cache_use_stale   error timeout invalid_header;
}

但是nginx不能再启动了

您好,我按照您的建议,nginx不能再启动了有错误,nginx会告诉您的。刚刚告诉我:*重新启动nginx nginx[fail]好的,我添加了一个遗漏;,并删除了一个代理缓存;,它已启动,但收到403禁止的错误。请将root指令移出位置,然后重新启动Nginx。将缓存设为禁用状态,直到完成为止。