T
T
tem12qaz2021-02-20 17:18:35
Nginx
tem12qaz, 2021-02-20 17:18:35

Can I read data in Nginx?

Let's say I have a dictionary like this:

dictionary = {
    'apple':8080,
    'car':8081,
    'pear':8082
}


Is it possible to configure the location block in nginx so that when connecting to host.ru/{dictionary key}
it will proxy to localhost:{dictionary value}?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Koryukov, 2021-02-20
@tem12qaz

You can, for this there is a map
construct that even knows how to pull options from a separate file
. However, this is a rather static option, suitable for cases where you just need to set it up and forget it.
If you need interactivity, then you can try to add it through the njs module - it allows you to write js code that sets the value of a variable.
However, this is a rather atypical option and 99% of its uses are crutches and bicycles.
In the case when you need proxying to a dynamically generated list of services, look towards various custom proxies and service discovery, such as HAProxy or Consul.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question