问题
I'm new in GCE, and I am confused about setting up the load balancer.
If I have two instances, serving on Port 9000, I want to setup a balancer that accepts on port 80, then route requests to my instances in port 9000..
a diagram like this..
LB:port:80 -> VM:port:9000
I have other load balancers from other providers which has a settings like pointing to VM's port. but in GCE, I cant seem to find it, or I am missing something..
I hope I am making a sense, here. thank you in advance
回答1:
It isn't possible in GCE to do a port rewriting. As a workaround I use port forwarding using iptables Then in GCE, you can create a health check on port 9000, your target pool will have your instances listing on port 9000 and your forwarding rule will be on port 80 with your target pool.
Another workaround will be to run HAProxy on the instance to locally forward port 80 on the instance to port 9000.
回答2:
If your app is HTTP-based (looks like it), then please have a look at the new HTTP load balancing announced in June. It can take incoming traffic at port 80 and forward to a user-specified port (eg. port 9000) on the backend. The doc link for the command is here:
https://developers.google.com/compute/docs/load-balancing/http/backend-service#creating_a_backend_service
Hope it helps.
来源:https://stackoverflow.com/questions/24656161/google-cloud-load-balancer-port-80-to-vm-instances-serving-port-9000