Welcome! Log In Create A New Profile

Advanced

Re: How to combine try_files with multiple proxy destinations

Francis Daly
January 09, 2014 04:46PM
On Wed, Jan 08, 2014 at 04:22:40AM -0500, rrrrcccc wrote:

Hi there,

(This is all untested, so handle with care.)

> I have the folllowing requirement:
> 1. if /usr/share/nginx/html/maintenance.html exists, then always show this
> file to browser.

That is probably best done with an "if" and a "return 503" -- there are a
few approaches you can take, with their own advantages and disadvantages.

> 2. if this is the static file which located in the sub-directories of
> /usr/share/nginx/html/, then show this static file to browser.
> 3. if the URI begins with /testapp1/, then proxy to http://127.0.0.1:8080;
> else proxy to http://127.0.0.1:8081

You could use "error_page" for 404 here, following
http://ngnix.org/r/error_page.

But I'll suggest using try_files with a named location as fallback.

Either way, you'll probably want one prefix and one named location,
per set of urls.

Something like:

location ^~ / {
try_files $uri $uri/ @proxyslash;
}
location @proxyslash {
proxy_pass http://127.0.0.1:8080;
}
location ^~ /testapp1/ {
try_files $uri $uri/ @proxytestapp1;
}
location @proxytestapp1 {
proxy_pass http://127.0.0.1:8081;
}

f
--
Francis Daly francis@daoine.org

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

How to combine try_files with multiple proxy destinations

rrrrcccc January 08, 2014 04:22AM

Re: How to combine try_files with multiple proxy destinations

Francis Daly January 09, 2014 04:46PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 304
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