Updating the proxy/load balancer

Now is the time to make a tremendous change to the application. When we talk about a big change, we are not talking so much at the code level, but rather at the level of impact it has for the application business and for the health of the system.

First, let's remove the upstream we had before. The configuration of the server had some problems, such as route collision and wrong routing:

upstream proxy_servers { 
        server bookproject_userservice_1:3000; 
        server bookproject_userservice_2:3000; 
        server bookproject_userservice_3:3000; 
        server bookproject_userservice_4:3000; 
        server bookproject_famous_news_service_1:5000; 
        server bookproject_famous_news_service_2:5000; 
        server bookproject_famous_news_service_3:5000; 
        server bookproject_famous_news_service_4:5000; 
        server bookproject_politics_news_service_1:5000; 
        server bookproject_politics_news_service_2:5000; 
        server bookproject_politics_news_service_3:5000; 
        server bookproject_politics_news_service_4:5000; 
        server bookproject_sports_news_service_1:5000; 
        server bookproject_sports_news_service_2:5000; 
        server bookproject_sports_news_service_3:5000; 
        server bookproject_sports_news_service_4:5000; 
}

After we remove the old upstream, we will create two different upstreams—one for users_service and another one for orchestrator_news_service. In this way, we are creating entirely separate routes. Note that before we recorded each microservice upstream, we now no longer need to work this way, because we have the orchestrator microservice that handles the data intelligently. Only the orchestrator is exposed to consumers of our microservices:

 
upstream users_servers { 
    server bookproject_usersservice_1:3000; 
    server bookproject_usersservice_2:3000; 
    server bookproject_usersservice_3:3000; 
    server bookproject_usersservice_4:3000; 
} 
 
upstream orchestrator_servers { 
    server bookproject_orchestrator_news_service_1:5000; 
    server bookproject_orchestrator_news_service_2:5000; 
    server bookproject_orchestrator_news_service_3:5000; 
    server bookproject_orchestrator_news_service_4:5000; 
}

Just as we have different upstreams, we will create different locations. This gives us more configuration flexibility and solves the problem of routes collision. Now, we have a location that redirects requests to the users_servers upstream, and a location that redirects requests to the orchestrator_servers upstream:

location / { 
    proxy_pass         http://users_servers/; 
    proxy_redirect     off; 
    proxy_set_header   Host $host; 
    proxy_set_header   X-Real-IP $remote_addr; 
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header   X-Forwarded-Host $server_name; 
} 
 
location /news/ { 
    proxy_pass         http://orchestrator_servers/; 
    proxy_redirect     off; 
    proxy_set_header   Host $host; 
    proxy_set_header   X-Real-IP $remote_addr; 
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header   X-Forwarded-Host $server_name; 
} 

At the end of our full nginx.conf, it has the following format:

worker_processes 4; 
 
events { worker_connections 1024; } 
 
http { 
    sendfile on; 
 
    upstream users_servers { 
        server bookproject_usersservice_1:3000; 
    } 
 
   upstream orchestrator_servers { 
        server bookproject_orchestrator_news_service_1:5000; 
    } 
 
    server { 
        listen 80; 
 
        location / { 
            proxy_pass         http://users_servers/; 
            proxy_redirect     off; 
            proxy_set_header   Host $host; 
            proxy_set_header   X-Real-IP $remote_addr; 
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for; 
            proxy_set_header   X-Forwarded-Host $server_name; 
        } 
 
         location /news/ { 
            proxy_pass         http://orchestrator_servers/; 
            proxy_redirect     off; 
            proxy_set_header   Host $host; 
            proxy_set_header   X-Real-IP $remote_addr; 
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for; 
            proxy_set_header   X-Forwarded-Host $server_name; 
        } 
    } 
} 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.49.190