3
回答
nginx 单tomcat下 两个项目 两个域名 设置
终于搞明白,存储TCO原来是这样算的>>>   
我现在的环境是两台服务器,每台服务器上各有一个tomcat,一个nginx,现在,是用nginx做的反向代理,基于sticky的cookie负载均衡,现在,有一个项目正常运转,我现在的问题是,我要在tomcat下加一个独立的项目,独立的域名。使该项目也实现基于sticky的负载均衡,应该怎么操作呢。
举报
舍得小弟
发帖于4年前 3回/4K+阅
共有3个答案 最后回答: 4年前

我原来是这么配置的

upstream web.xxx.com  {
         sticky;
         server 192.168.1.171:8080 max_fails=1 fail_timeout=10s;
         server 192.168.1.175:8080 max_fails=1 fail_timeout=10s;
    }
       

   server {
        listen       80;
        server_name  web.xxx.com;

        location / {
                proxy_pass http://web.xxx.com/;

                proxy_set_header   Host    $host;
                proxy_set_header   X-Real-IP   $remote_addr;
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for; 
                proxy_connect_timeout   1;
                proxy_read_timeout      30;
        }


        location /img {
                root /usr/local/www/nginx;
                proxy_connect_timeout   1;
                proxy_read_timeout      10;
        }

        rewrite ^(.*)\;jsessionid=(.*)$ $1 break;

        underscores_in_headers on;
}


 现在 我新加了个server

 

server {
        listen       80;
        server_name  store.xxx.com;

        location / {
                proxy_pass http://192.168.1.171:8080/store/;
                proxy_redirect off;
                proxy_set_header   Host    $host;
                proxy_set_header   X-Real-IP   $remote_addr;
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_connect_timeout   1;
                proxy_read_timeout      30;        }

        location /img {
                root /usr/local/www/nginx;
                proxy_connect_timeout   1;
                proxy_read_timeout      10;
        }
             rewrite ^(.*)\;jsessionid=(.*)$ $1 break;

        underscores_in_headers on;
}
     

 

但是,现在还是不行,我输入web.xxx.com 能正常访问,输入store.xxx.com,地址栏这样显示:http://store.xxx.com/store/login.jsp;jsessionid=91E4000AF6BD060B1B2A77AD81A88F5B-n1

并且改网站显示正常,一些图片都没有显示出来,我已经把图片拷贝到了/usr/local/www/nginx/img下,不应该不显示。

store.xxx.com to 192.168.1.171:8080: "GET /favicon.ico HTTP/1.1" 302 0 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET4.0C; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)" "-" upstream_response_time 0.002 msec 1388658595.356 request_time 0.002cookies -
[02/Jan/2014:18:29:55 +0800] 192.168.1.127 - - - store.xxx.com to 192.168.1.171:8080: "GET /store/login.jsp;jsessionid=1C67DCC0B43FCBDEEFA336504156162C-n1 HTTP/1.1" 200 969 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET4.0C; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)" "-" upstream_response_time 0.004 msec 1388658595.362 request_time 0.004cookies JSESSIONID=1C67DCC0B43FCBDEEFA336504156162C-n1

 

顶部