Welcome! Log In Create A New Profile

Advanced

How to combine try_files with multiple proxy destinations

January 08, 2014 04:22AM
I have the folllowing requirement:
1. if /usr/share/nginx/html/maintenance.html exists, then always show this file to browser.
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

And I tried the following two configurations but both failed:
1. Config1
server {
...
root /usr/share/nginx/html/;
location / {
try_files /maintenance.html $uri @proxy;
}

location @proxy {
location /testapp/ {
proxy_pass http://127.0.0.1:8080;
}

location / {
proxy_pass http://127.0.0.1:8081
}
}
}

2. Config2
server {
...
root /usr/share/nginx/html/;
try_files /maintenance.html $uri @proxy;

location /testapp/ {
proxy_pass http://127.0.0.1:8080;
}

location / {
proxy_pass http://127.0.0.1:8081
}
}

For Config1, it throws the following error:
nginx: [emerg] location "/testapp/" cannot be inside the named location "@proxy" in /etc/nginx/nginx.conf:41

For Config2, it does not work as expected: it seems that when try_files is together with location directives, try_file has the lowerest priority and so I can never get /maintenance.html shown.

So can anybody know how to config to meet my requirement ? Thanks in advance!
SubjectAuthorPosted

How to combine try_files with multiple proxy destinations

rrrrccccJanuary 08, 2014 04:22AM

Re: How to combine try_files with multiple proxy destinations

Francis DalyJanuary 09, 2014 04:46PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 61
Record Number of Users: 7 on March 06, 2014
Record Number of Guests: 229 on August 01, 2014
Powered by nginx    Powered by FreeBSD    PHP Powered    Powered by Percona     ipv6 ready