upstream backend {
server domain1.com/path1;
server domain2.com/path/path2;
server domain3.com/pah3;
}
location @ {
proxy_pass https://backend;
proxy_ssl_trusted_certificate /etc/nginx/sslcerts/backend.server.pem;
proxy_ssl_verify off;
}
was trying to load balance traffic to all servers in backend, getting error as invalid host in upstream
is there any other way to configure nginX to meet this requirement.
CodePudding user response:
Upstream does not take paths. Don't know why you're using a named location here (@)?!
upstream backend {
server domain1.com;
server domain2.com;
server domain3.com;
}
location / {
proxy_pass https://backend/path1;
proxy_ssl_trusted_certificate /etc/nginx/sslcerts/backend.server.pem;
proxy_ssl_verify off;
}
You have to use the same path on the backends or at least forward from this path to the right one..
If you rely on different paths and you can't touch the backend servers try this (hacky) work-around:
upsteam virtualloadbalancer {
server 127.0.1.1;
server 127.0.1.2;
server 127.0.1.3;
}
server {
listen 127.0.1.1;
location / {
proxy_pass http://domain1.com/path1;
}
}
server {
listen 127.0.1.2;
location / {
proxy_pass http://domain2.com/path2/path;
}
}
server {
listen 127.0.1.3;
location / {
proxy_pass http://domain3.com/path3;
}
}
server {
listen 80;
location / {
proxy_pass http://virtualloadbalancer;
proxy_next_upstream error | timeout | invalid_header | http_500 | http_502 | http_503 | http_504 | http_403 | http_404 | http_429
}
}