Himanshu
Himanshu

Reputation: 363

Modifying nginx config directly in memory?

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

Upvotes: 2

Views: 1625

Answers (1)

Pixou
Pixou

Reputation: 1769

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

Upvotes: 1

Related Questions