Loadbalancing with nginx and tomcat
- by London
Hello this should be fairly easy to answer for any system admin, the problem is that I'm not server admin but I have to complete this task, I'm very close but still not managing to do it. Here is what I mean, I have two tomcat instance running on machine1 and machine2. People usually access those by visiting urls :
http://machine1:8080/appName
http://machine2:9090/appName
The problem is when I setup nginx with domain name i.e domain.com, nginx sends requests to http://machine1:8080/ and http://machine2:9090/ instead of http://machine1:8080/ and http://machine2:9090/appName
Here is my configuration (very basic as it can be noted) :
upstream backend {
server machine1:8080;
server machine2:9090;
}
server {
listen 80;
server_name www.mydomain.com mydomain.com;
location / {
# needed to forward user's IP address to rails
proxy_set_header X-Real-IP $remote_addr;
# needed for HTTPS
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_max_temp_file_size 0;
proxy_pass http://backend;
} #end location
} #end server
What changes must I do to do the following :
- when user visits mydomain.com
- transfer him to either machine1:8080/appName or machine2:9090
Thank you