Trying to build simple example of using NGINX as a load balancer, i am getting the error when starting:
[emerg] 1#1: host not found in upstream "server.two:8088" in /etc/nginx/conf.d/alb.conf:27
I know that this issue can be related to the server which is not running when the upstream is upping.
So my question is -- Is there solution on how to run NGINX servers before upstream is upping? Or is there any solution how it can be fixed in other way?
My env is:
- Win 10
- WSL2
- Docker
docker-compose.yml
contains:
version: "3"
services:
app:
image: nginx:1.25.2
container_name: "load_balancer_nginx"
ports:
- "80:80"
- "8000:8000"
volumes:
- ../src/:/var/www/html:rw
- ../nginx/nginx.conf:/etc/nginx/nginx.conf
- ../nginx/default.conf:/etc/nginx/conf.d/default.conf
- ../nginx/alb.conf:/etc/nginx/conf.d/alb.conf # Application Load Balancer
alb.conf
:
server {
listen 8000;
server_name server.one;
root /var/www/html/server.one/;
charset utf-8;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
server {
listen 8088;
server_name server.two;
root /var/www/html/server.two/;
charset utf-8;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
upstream all {
server server.one:8000;
server server.two:8088;
}
server {
listen 80;
server_name magento_alb.loc;
absolute_redirect off;
location / {
proxy_pass http://all/;
proxy_pass_request_headers on;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_intercept_errors on;
proxy_cache off;
}
}
default.conf
:
#nothing. just to rewrite the existing one.
nginx.conf
:
events {}
http {
include /etc/nginx/conf.d/*.conf;
}
a) Trying to start docker container without errors, But i am facing with errors.
b) have tried to use the variable but also without any success( still getting the same error ) set $backend_servers all; proxy_pass http://$backend_servers;
c) have tried to use the map -- no success ( i am getting the same error ) map $scheme $server_two { default server.two:8088; } upstream all { server server.one:8000; server $server_two; }
d) Used the fail_timeout & max_fails
-- the same error
upstream all {
server server.one:8000 fail_timeout=999s max_fails=999999;
server server.two:8088 fail_timeout=999s max_fails=999999;
}