I am trying to use the rewrite engine of nginx to redirect requests.
On the same machine I have a Jetty running on port 8080, which is delivering some content.
I want to check if the content is available on Jetty otherwise I want to redirect it.
For that I have to locations added, one is used for the redirect on the Jetty and the other should check it.
location /nexus/ {
rewrite ^/nexus/(.*)$ http://A:8080/nexus/$1 permanent;
}
location ~* "^/releases/([a-z]*)/(.*)$" {
try_files /nexus/content/repositories nexus/content/repositories /nexus/content/;
# rewrite ^/releases/test/(.*)$ http://A:8080/nexus/content/repositories/Test/$2 break;
}
My idea was to use try_files, but the first parameters should be files or directories.
Is there any other method to test if an URL is accessible?
At the moment I am using Nginx for checking the reachable of the URL, perhaps I can better use Jetty, which is in front of Nexus.
Nginx was just a choice and if there are better possibilities, I am willing to switch. :)
Here some details about the environment:
You are describing the caching reverse proxy pattern, which Nginx can be configured to do. The local cache is first checked, and then if the file there is missing or stale, a copy is fetched from a backend server and possibly also cached locally.
I recommend reviewing the Nginx proxy module docs. Once the problem is described in those terms, a number of tutorials can be found with examples, Here's a detailed article on getting up Nginx as a reverse proxy, with caching enabled.