nginx +tomcat 多域名共享端口

  1. http{
  2. upstream test1 {    
  3.         server 192.168.0.1:81 weight=1;              
  4. }    
  5.   
  6. #第二个网站的
  7. upstream test2 {    
  8.         server 192.168.1.1:8080 ;   
  9.  }    
  10.   
  11. #同一服务器转发2个不同域名进行负载均衡  
  12. server  
  13.   {  
  14.     listen       80;  
  15.     server_name  test1; test1.aaa.com  
  16.         location / {    
  17.             index  index.html index.jsp;    
  18.             #这里的proxy_pass转发的是upstream的名字www.aaa.com  
  19.             proxy_pass  http://test1;    
  20.             proxy_set_header    X-Real-IP   $remote_addr;    
  21.             client_max_body_size    100m;    
  22.         }    
  23. }  
  24.   
  25. server  
  26.   {  
  27.     listen       80;  
  28.     server_name  www.test2.com;  
  29.         location / {    
  30.             index  index.html index.jsp;    
  31.             proxy_pass  http://test2;    
  32.             proxy_set_header    X-Real-IP   $remote_addr;    
  33.             client_max_body_size    100m;   
  34.            }
  35.         }
  36. #######下面是直接赚了一个静态网站
  37. server

  38. listen 80 ;

  39. server_name test.com;
  40. charset UTF-8;
  41. root /website/vshopxx;
  42. location /{
  43. index index.html;
  44. }

  45. error_page 500 502 503 504 /50x.html;

  46. location = /50x.html {

  47. root html;}

  48. }

  49. #########
  50. server {
    listen 80 ;
    server_name coin.vip www.coin.vip;
    charset UTF-8;
    root /website/index/;
    location / {
    # index index.html;

    # root /website/index;
    index index.html;
    try_files $uri $uri/ /index.html;
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }
    }

在nginx.conf 中添加如上

我是用yum装的nginx,默认的配置文件在usr\...\nginx.conf 不是、/etc/nginx/nginx.conf!!!!,  启动的时候用nginx -c  /etc/nginx/nginx.conf 才会按照新的配置文件启动

参考链接 http://www.linuxde.net/2012/06/11006.html

  http://www.nginx.cn/doc/

 

整个

posted @ 2017-08-23 10:07  Qtong  阅读(255)  评论(0)    收藏  举报