How to serve all existing static files directly with NGINX, but proxy other requests to jetty?

AlexLuya nginx-forum at
Tue Nov 18 15:05:26 UTC 2014

My question is similar to,different
is that my site directory structure looks like this:


So the site root isn't "/nginxRoot/" but "/nginxRoot/test/"

I want to nginx to serve all static files that have been put at
directories:js,images,html,and proxy other requests to jetty,I have tried:

location ~ ^/test/(.*)\.  
    root  /ngixRoot/test;

 location ~ ^/test/(.*)$ {
    proxy_redirect off;

All requests to jetty works,but all requests to static files don't,I doubt
they are forwarded to jetty also,is that true?how to fix this problem?

After a squence of Q&A,I was told that "try_files" is  another option(not
sure which one is more propriate for my use case ),then after googling and
reading,I tried this:

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

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

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

but get "403 forbidden" error,so please tell me what I did wrong?Thanks.

Posted at Nginx Forum:,254884,254884#msg-254884

More information about the nginx mailing list