Question

I am using this tutorial but instead of plain server:port I am specifying app directory, but it is giving the below exception

nginx: [emerg] invalid host in upstream "localhost:9090/pa" in C:\app\abhishek\nginx_test\nginxc1/conf/nginx.conf:18

I am using nginx as my load balance and tomcat as my webserver. I am able to access my tomcat webapp using http://localhost:9090/pa and http://localhost:10080/pa.

Here is my nginx.conf file

#user  nobody;
worker_processes  1;

error_log  logs/error.log  info;

events {
    worker_connections  1024;
}


http {

    #keepalive_timeout  0;
    keepalive_timeout  75;

    upstream balancer {
        server localhost:9090/pa weight=2;
        server localhost:10080/pa;
    }

    server {
        listen       6789;
        server_name  localhost;

        location /bal/ {
            proxy_pass http://balancer;
        }

        error_page   500 502 503 504 404  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

}
Was it helpful?

Solution

Upstream declares only host and port. Path is a part of proxy_pass. So your config should look like this:

upstream balancer {
    server localhost:9090 weight=2;
    server localhost:10080;
}

...

location /bal/ {
    proxy_pass http://balancer/pa/;
}

Also, be careful with trailing slashes, generally you use or don't use them in location and proxy_pass simultaneously.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top