A
A
Anton Ivanov2017-06-14 21:43:50
Nginx
Anton Ivanov, 2017-06-14 21:43:50

Which configuration option for nginx is more logical and preferable?

Hello.
As they said before, "I want strange things."
For home needs, I made a configuration when several domains look at my ip. Moreover, I can dynamically reassign home directories for these domains (settings in the database). That is, at some point, all domains have one home directory, then I assign another directory to one domain. Then I assign my directory to another one. Then I add a new domain with one more home directory. The question arose of how to resolve the routing, since I do not want to use the backend for routing. Too easy)))
While I have 2 solutions, both are already written and tested.
1. Through the map file for nginx. That is, with any sneeze in the direction of domain settings (adding a new one, changing the working directory, and so on), a new map file is generated for nginx with the corresponding host - root_dir and a new file with a list of hosts that are processed by this config. A semaphore is also created, to which every minute script in the cron reacts, which reloads nginx.
2. Through the lua script in the nginx config, which crawls into the radish, if there is no entry for the domain, then it crawls into postgres, takes the corresponding entry from there, adds it to the radish with a timeout, say, 5 minutes and prescribes the correct root for nginx
It works this way and that, but I thought, which of these has the right to life more? What if there are several thousand domains? Several tens of thousands? Several hundred thousand? )))) Of course, this will not happen, but I want to understand the weaknesses of each solution (or maybe there is another solution that is optimal?)
In the first option, I see a problem in a too large map file. How fast will nginx process a poppy file that is a couple of megabytes in size? In the second option - constant requests to the database. You can, of course, cache records not for a separate domain, but for all, then we will reduce the number of requests to postgres, but "stretch" redis :)
This is such an interesting (for me) task :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2017-06-14
@BorisKorobkov

A file with one line "root ...". It is included from the domain config.
When changing the path, regenerate the first file or reload nginx.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question