1

This nginx configuration works for me:

location /foo/ {
  proxy_pass http://a.bar.mesos/;
}

Note that both the location selector and the proxy_pass value are URIs. So you know, this affects how the URL is rewritten for the upstream server. As an example, http://.../foo/bar gets rewritten to http://a.bar.mesos/bar. If the proxy_pass value were http://a.bar.mesos without the trailing slash then the URL would be rewritten as http://a.bar.mesos/foo/bar which is incorrect for me.

As you may also know, if a.bar.mesos is not resolvable at nginx start time then nginx will not start. A way around this is mentioned in other questions on this site and it is to use a resolver directive and a variable like so:

location /foo/ {
  resolver 127.0.0.1;
  set $a_bar_mesos a.bar.mesos;
  proxy_pass http://$a_bar_mesos/;
}

Indeed this solves the problem of nginx not starting with an unresolvable host name but it also makes nginx no longer recognize that the proxy_pass value has a URI and so URL rewriting becomes incorrect for me. That is, it use the rewriting rules associated with a proxy_pass value of http://a.bar.mesos instead of http://a.bar.mesos/.

My question is, does anyone know how to start nginx with unresolvable host names and get the URI/URI URL rewriting rules?

So you know my use case, I use Mesos to launch programs onto a cluster of machines. The programs have well known names like a.bar. I use mesos-dns then to associate the program name a.bar with the hostname a.bar.mesos and the IP address of the machine that Mesos assigned to it. When the program is not running, mesos-dns removes the name a.bar.mesos from its registry. I use nginx to forward HTTP requests to the program via the above configuration. When I am restarting the server hosting nginx there is no guarantee that all of the programs being proxied to will be up and running.

1 Answer 1

0

You can implement the URI/URI rewrite rule by using a rewrite ... break inside the same location, rather than using the proxy_pass to do it for you:

location /foo/ {
    resolver 127.0.0.1;
    set $a_bar_mesos a.bar.mesos;

    rewrite ^/foo(.*)$ $1 break;
    proxy_pass http://$a_bar_mesos;
}

See this document for details.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.