Welcome! Log In Create A New Profile

Advanced

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

November 18, 2014 10:05AM
My question is similar to http://stackoverflow.com/questions/869001/how-to-serve-all-existing-static-files-directly-with-nginx-but-proxy-to-apache,different is that my site directory structure looks like this:

/nginxRoot/test/js
/nginxRoot/test/images
/nginxRoot/test/html
........

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/(.*)\. (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;
}

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 {
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_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.
Subject Author Posted

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

AlexLuya November 18, 2014 10:05AM

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

Francis Daly November 18, 2014 03:54PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 196
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready