Answer the question
In order to leave comments, you need to log in
How to resolve hostname in Docker for nginx if container is not running?
I can't find a solution for a seemingly trivial situation. There are several application containers that are proxied by nginx - a classic scheme. In the solution, a situation is possible when certain applications will be idle disabled. In principle, this should also be a common situation (for example, when the application is under maintenance or under development). This is not about a specific time, it is clear that for a while you can keep waiting for nginx and use a backup server if the shutdown occurs while nginx is running. Here is an example of a conditional configuration:
upstream server_1 {
server app_1:10;
}
upstream server_2 {
server app_2:20;
# можно задать разные опции, ожидание, количество попыток и даже backup-сервер, не принципиально
}
# ... еще некоторые приложения
server {
# ... пропускаю типовую конфигурацию, она рабочая
location /server_1 {
proxy_pass http://server_1;
# ... заголовки и прочее
}
location /server_2 {
proxy_pass http://server_2;
}
# ... еще сколько-то точек входа
# можно попробовать и такой вариант, без upstream, итог не меняется:
location /server_N {
proxy_pass http://app_N:100;
}
}
host not found in upstream app_1
upstream server_1 {
server 172.18.0.2:10;
server mainetnance:500 backup;
}
set $srv1 = http://app1:10;
...
proxy_pass $srv1;
Answer the question
In order to leave comments, you need to log in
try with a variable:
set $srv1 = http://app1:10;
...
proxy_pass $srv1;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question