0

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:

enter image description here

CSchulz
  • 243
  • 3
  • 20

1 Answers1

0

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.

Mark Stosberg
  • 3,901
  • 24
  • 28
  • Thanks for your answer. Can I use upstream with rewrite? I have two different backend server, which are using different URLs. – CSchulz Aug 15 '13 at 13:48
  • `upstream` defines /servers/ and ports to connect to, not URIs. All your backend servers should be set to respond to the same URI requests. – Mark Stosberg Aug 15 '13 at 15:20
  • Sure you are right, but the "backup" server isn't managed by me. It is a public server. We are mirroring that server to reduce the traffic going over WAN. – CSchulz Aug 15 '13 at 15:30
  • It sounds like you want to set up Nginx as a caching proxy in that case. – Mark Stosberg Aug 15 '13 at 15:35
  • I have updated my question. Nginx was just a choice, perhaps the integrated Jetty is the better choice, but I have to start somewhere. Nginx shall look for the data on the upstream server and if it can't find them send the request to the external server. – CSchulz Aug 15 '13 at 15:50