2

This might be a very silly question but I'll still ask it. Nginx reads nginx.conf file & keeps information in memory/cache until you do a 'nginx -s reload'. Is there a way were I can modify nginx configuration directly in memory as I need to do reload multiple times per minute and config file can be huge.

Basically the problem I'm trying to solve is that I have multiple docker containers coming up & down dynamically on a set of host machines. Every time a container comes up, it'll have a different IP & port open (application design constraint). And I'm thinking of using Nginx as reverse proxy. What should I do to solve this problem considering the fact that final product might have 3000 - 5000 containers running on a cluster of hosts. The rate at which containers are launched/destroyed might be around 100 per second.I need a fast way to make sure routing is happening properly

Himanshu
  • 363
  • 1
  • 4
  • 17
  • This looks like an example of the XY Problem (xyproblem.info). The real question here is why do you have to reload several times a minute. – Dayo May 21 '15 at 04:00
  • @Dayo I am trying to do a POC where lot of docker containers are coming up and down dynamically. Need to route requests to the right container – Himanshu May 21 '15 at 08:56
  • In which case you should edit the question to ask for help with your actual problem. – Dayo May 21 '15 at 10:05
  • Thanks @Dayo for suggestion. Updated problem statement. – Himanshu May 21 '15 at 11:37

1 Answers1

1

hmmm, probably not, nginx loads its config in multiple workers, so this does not look like a good idea to try to change it on the fly.

What it your goal ? You seem to need to do some dynamic routing or other sort of treatment. You should instead look at:

  • nginx directives and modules such as eval
  • Lua scripting
  • nginx module dev (in C/C++)

This would allow you to do more or less whatever you want, you can read some config in a db like redis, and change the behavior of your code according to the value in Redis.

For example, you could do a lot just by reading a value in Redis, and then use if directive in your nginx config file. You can use How can I get the value from Redis and put it in a variable in NGiNX? to get redis value in nginx with eval module.

UPDATE :

For dynamic IP in nginx, you should look at Dynamic proxy_pass to $var with nginx 1.0. So I would suggest that you :

  • have a process that write in redis the IP address of your dockers
  • read it with eval and redis module in nginx
  • use the value to proxy
Community
  • 1
  • 1
Pixou
  • 1,719
  • 13
  • 23