A
A
Alexey2012-12-19 17:49:17
Nginx
Alexey, 2012-12-19 17:49:17

Using variable in proxy_pass?

There is nginx 1.014, it is necessary to proxy depending on the subdomain to a specific machine within the network.
On the Internet, examples of the form are everywhere:

location /proxy {
    resolver 8.8.8.8;
    set $target http://proxytarget.example.com;
    proxy_pass $target;
}

So I do the same for myself:
location / {
  set_by_lua $target "return  string.gsub(ngx.var.host, 'host.ru', '-host')";
  proxy_pass $target;
  proxy_set_header Host $host;
}

But this solution does not work, it constantly throws out 404.
If you specify the path instead of a variable, then everything is fine.
inner-host - hard coded in hosts.
I don't understand where to dig :/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2012-12-20
@fuCtor

Yes, now I figured it out, I completely forgot about this log. It turned out that nginx does not know how to look at hosts, I had to install dnsmasq and set resolver to 127.0.0.1.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question