一个tomcat和nginx部署多个工程

目的是为了在一个nginx和一个tomcat下面配置多个应用,使用同一个ip和端口加上不同的路径访问。

worker_processes  1;
 
events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

   upstream order {
         server 192.168.52.111:7478;
    }
   upstream user {
         server 192.168.52.111:7478;
    }


    server {
  #监听的端口
        listen       9876;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
#Location 指令,是用来为匹配的 URI 进行配置,URI 即语法中的"/uri/",可以是字符串或正则表达式。但如果要使用正则表达式,则必须指定前缀。但是好像我都匹配不到也能转发,不知道都找不到时候的逻辑/userinfo是自己配置的随便要转发的路径tomcat下面的webapps下面的工程的文件夹的名称
      location /userbase {
            root   html;
            proxy_pass  http://user/userinfo;
            proxy_set_header  X-Real-IP  $remote_addr;
            client_max_body_size  100m;
            index  index.html index.htm;
        }
        location /orderbase {
            root   html;
            proxy_pass  http://order/orderinfo;
            proxy_set_header  X-Real-IP  $remote_addr;
            client_max_body_size  100m;
            index  index.html index.htm;
        }
 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

}

 通过上面配置,工程访问路径为http://ip: 9876/userinfo 和 http://ip: 9876/orderinfo

猜你喜欢

转载自ztreal.iteye.com/blog/1704334