Welcome! Log In Create A New Profile

Advanced

Re: Does Nginx honor DNS TTLs for proxy upstreams?

csg
September 28, 2011 12:05PM
Maxim Dounin Wrote:
-------------------------------------------------------
> Errors suggest you don't have $backend set, and
> resulting
> proxy_pass tries to go to "http://" which is
> invalid.

Yup, I am just curious how to accomplish that if you want to perform some rewriting before, for example to strip off some leading parts of the URL path. I came up with following test case:

worker_processes 3;

events {
worker_connections 1024;
}

http {
server_tokens off;

include nginx.mime.types;
default_type application/octet-stream;

sendfile on;
keepalive_timeout 15;

server {
listen 0.0.0.0:90;
server_name _;

location / {
root html;
index index.html;
}
}

server {
listen 0.0.0.0:91;
server_name _;

location / {
rewrite ^/foo/(.*)$ /$1 break;

proxy_pass http://localhost:90;
proxy_redirect off;
}
}

server {
listen 0.0.0.0:92;
server_name _;

location / {
rewrite ^/foo/(.*)$ /$1 break;

resolver 127.0.0.1;

set $backend "localhost:90";
proxy_pass http://$backend;
proxy_redirect off;
}

error_log /var/log/nginx/error.log debug;
}
}

The port 91 server is a reverse proxy to the port 90 server with static upstream (DNS lookup only on startup/reload). I delivers happily the index.html of the port 90 server, regardless if I request http://localhost:91/ of http://localhost:91/foo/.

Bringing the resolver into play doesn't seem to be that straight forward if you look at the port 92 reverse proxy. It works when no rewriting has to be performed, i.e., http://localhost:92/ works. But if I want to strip off the leading /foo/ URL path segment of the request http://localhost:92/foo/.

2011/09/28 17:55:51 [notice] 1490#0: *2 "^/foo/(.*)$" matches "/foo/", client: 127.0.0.1, server: _, request: "GET /foo/ HTTP/1.1", host: "localhost:92"
2011/09/28 17:55:51 [notice] 1490#0: *2 rewritten data: "/", args: "", client: 127.0.0.1, server: _, request: "GET /foo/ HTTP/1.1", host: "localhost:92"
2011/09/28 17:55:51 [warn] 1490#0: *2 using uninitialized "backend" variable, client: 127.0.0.1, server: _, request: "GET /foo/ HTTP/1.1", host: "localhost:92"
2011/09/28 17:55:51 [error] 1490#0: *2 invalid URL prefix in "http://", client: 127.0.0.1, server: _, request: "GET /foo/ HTTP/1.1", host: "localhost:92"

Any hints how to solve this the easiest way? Basically me requirement is to reverse proxy http://proxy.example.com/foo/bar/quux to http://upstream.example.com/bar/quux (so strip off "foo/") while the IP of upstream.example.com can change over time without prior announcement.
Subject Author Posted

Does Nginx honor DNS TTLs for proxy upstreams?

csg September 26, 2011 04:42AM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

Maxim Dounin September 26, 2011 05:38AM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

csg September 26, 2011 09:40AM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

Maxim Dounin September 26, 2011 09:58AM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

csg September 28, 2011 12:05PM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

Maxim Dounin September 28, 2011 12:14PM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

csg September 28, 2011 03:35PM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

csg September 29, 2011 03:31AM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

csg September 29, 2011 03:32AM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

csg September 29, 2011 03:53AM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

Maxim Dounin September 29, 2011 03:30AM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

csg October 04, 2011 04:12AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 98
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready