| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1065 人关注过本帖
标题:在Windows环境中使用Nginx配置反向代理和负载均衡
只看楼主 加入收藏
堕落黑天使
Rank: 1
等 级:新手上路
帖 子:84
专家分:0
注 册:2016-12-22
结帖率:0
收藏
 问题点数:0 回复次数:0 
在Windows环境中使用Nginx配置反向代理和负载均衡
修改/ conf/ nginx.conf配置文件。Nginx运行起来。
\\
 
访问localhost:8000/index.html会直接访问发布的静态文件。访问localhost:8000/api/index.html会被轮询分配到localhost:8005/index.html和localhost:8006/index.html。这样就能保证前端和后端服务在同源下,彻底解决跨域问题。同时api还实现了负载均衡,减轻了服务器压力。
设置服务端cookie的path和domain。
\\
涉及配置文件内容:
 #设定负载均衡的服务器列表
         #weight越大,负载的权重就越大。8006的访问量是8005的两倍
         upstream targetserver{
                   #ip_hash;#按访问ip的hash结果分配,解决Session跨服务器问题
                   server localhost:8005 weight=1;
                   server localhost:8006 weight=2;
         }
 
location ^~ /api/ {
            #proxy_pass    http://localhost:8006;#反向代理方式1
            proxy_pass  http://targetserver; #反向代理2,也可做负载均衡。
            #proxy_redirect default ;
            proxy_redirect off ;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            client_max_body_size 50m;
            client_body_buffer_size 256k;
            proxy_connect_timeout30;
            proxy_send_timeout30;
            proxy_read_timeout60;
            proxy_buffer_size 256k;
            proxy_buffers4 256k;
            proxy_busy_buffers_size 256k;
            proxy_temp_file_write_size 256k;
            proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
            proxy_max_temp_file_size 128m;                           
            rewrite/api/(.+)$ /$1 break;#将/api/后面的路由直接转发到目标服务器的根目录
        }
                  
  location/ {
              autoindex on;
        index index.html index.htm;
              root "E:\02源代码管理\技术文档\AngularJsDemo";   
        }

原文链接:http://www.    北京网站建设
搜索更多相关主题的帖子: localhost Windows 服务器列表 配置文件 cookie 
2017-04-13 10:42
快速回复:在Windows环境中使用Nginx配置反向代理和负载均衡
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017248 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved