I'm trying to package 2 applications that use nginx as a proxy and deliver each a config file into /etc/nginx/conf.d/
.
Doing this in one file (combined.conf
) works great :
upstream backend1 {
http://localhost:8989;
}
upstream backend2 {
http://localhost:8990;
}
server {
location /backend1/ {
proxy_pass http://backend1;
}
location /backend2/ {
proxy_pass http://backend2;
}
However, when splitting into 2 files, one of the redirects fails systematically:
backend1.conf
:upstream backend1 { http://localhost:8989; } server { location /backend1/ { proxy_pass http://backend1; }
backend2.conf
:upstream backend2 { http://localhost:8990; } server { location /backend2/ { proxy_pass http://backend2; }
So my question is : can an http
node have 2 different server
childs ?
Nginx documentation says nothing about it.
Other people seem to have succeeded with this kind of architecture though :(
Nginx version is 1.1.19-1ubuntu0.1.
Thanks for any advice !
after so rumbling & testing, I figured a way to make it work and be able to ship one config file per application.
Here it is, dispatched in one common file and a pair of upstream/location files per application:
/etc/nginx/conf.d/common-proxies.conf
:/etc/nginx/locations/backend1.conf
/etc/nginx/locations/backend2.conf
/etc/nginx/upstreams/backend1.conf
/etc/nginx/upstreams/backend2.conf
A http block can have many server children. However, nginx selects one server block to process a request. So, the request never 'sees' the backend2 location because it matches against the first server block.
Here is one such solution that works for me with basic authentication.
Install required packages to generate passwords using htpasswd
create password files with below commands
nginx.conf file
Now deploying backend docker containers to be served by front-end nginx load-balancer
Glances container is a combination of top/htop for getting system/docker resources on console or on web browser.
Deploying Front-end nginx load-balancer to serve backend services/containers