Using Nginx on windows to load balance and reverse proxy. Trying to get load balancing working on local machine. I have two applications running on https://localhost:44308/ and https://localhost:44309/.
But I get the following error:
Bad Request - Invalid Hostname
Here is my nginx.conf:
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
keepalive_timeout 65;
upstream samplecluster {
server localhost:44308;
server localhost:44309;
}
server {
listen 8070;
server_name example.com;
location /api/values {
proxy_pass https://samplecluster;
}
}
So now when I try to access http://example.com:8070/api/values, I get the error.
It works fine when not using the load balancer.
location /api/values {
proxy_pass https://localhost:44308;
}
Note: 127.0.0.1->example.com in host file
2
Answers
It seems the error is coming from your services running on ports 44308 and 44309. The problem likely is they accept only a configured set of hosts, and localhost is one (if not the only one) that works.
So you simply need to set the
Host
header to pass it through:http://nginx.org/en/docs/windows.html
NGINX on Windows does not support the UDP proxy functionality.
location / {
proxy_pass xxxxx
}
is success
location /ddd {
proxy_pass xxxxx
}
is failed.
there are some issues with the win nginx proxy feature and the official website has explained.