nginx可以重新加载文件的。我们直接运行:nginx -s reload

配置文件有没有问题,可以直接输入:nginx -t

nginx -s stop就可以关闭

但有时我们就不想它挂的时候访问另外一个,而只是希望一个服务器访问的机会比另外一个大,使用weight

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#gzip  on;
 
    #一个服务器挂了,多配置一个jetty,weight=数字来指定,数字越大,表明请求到的机会越大
 
    upstream local_tomcat { 
            server localhost:8080 weight=1;
            server localhost:9999 weight=5;
    server{
        listen       8030;
        server_name  localhost:8080;
        #charset koi8-r;
       #access_log  logs/host.access.log  main;
        location / {proxy_pass http://local_tomcat;} 
        ##......其他省略
        #过滤不同的jsp和静态html页面
        #location / {  proxy_pass http://localhost:8080;}
        #location ~ .jsp$ {    proxy_pass http://localhost:8080;} 
        #location ~ .(html|js|css|png|gif)$ {  root D:/apache-tomcat-7.0.77/webapps/ROOT;}
        error_page   500 502 503 504  /50x.html;
 
        location = /50x.html {
 
            root   html;
 
        }
 
    }

<wiz_tmp_tag class="wiz-block-scroll">

 

1、nginx能做反向代理,那么什么是反向代理呢,举个栗子,我想在本地使用 www.mickey.com 的域名去访问 www.taobao.com。那么这个时候我们就可以通过nginx去实现。

2、nginx能实现负载均衡,什么是负载均衡呢?就是我的项目部署在不同的服务器上,但是通过统一的域名进入,nginx则对请求进行分发,减轻了服务器的压力。

3、作为安全隔离的作用;

4、解决跨域问题。

5、缓存静态文件,加快访问速度。

修改nginx.conf 配置文件,启用 upstream 负载均衡 tomcat Cluster,默认使用轮询方式。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
upstream site { 
    server localhost:8080;
    server localhost:9090;
 
server {
    listen       80;
    server_name  localhost;
 
    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
 
    location / {
        #root   /usr/share/nginx/html;
        #index  index.html index.htm;
        index  index_tel.jsp index.jsp index.html index.htm ; 
        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;   
        client_max_body_size    10m;   
        client_body_buffer_size 128k;   
        proxy_buffers           32 4k; 
        proxy_connect_timeout   3;   
        proxy_send_timeout      30;   
        proxy_read_timeout      30;  
            proxy_pass http://site;
 
    }

<wiz_tmp_tag class="wiz-block-scroll">

 

测试:

1、访问 http://10.129.221.70:8080 直接请求到tomcat_1服务器,显示 “ response from tomcat_1 ”, session 值为 ‘56E2FAE376A47F1C0961D722326B8423’;

2、访问 http://10.129.221.70:9090 直接请求到tomcat_2服务器,显示 “ response from tomcat_2 ”, session 值为 ‘56E2FAE376A47F1C0961D722326B8423’;

3、访问 http://10.129.221.70 (默认80端口)请求到 nginx 反向代理到指定Web服务器,由于默认使用轮询负载方式,反复刷新页面显示的内容在“ response from tomcat_1 ” 和 “ response from tomcat_2 ”之间切换,但 session 值保持为 ‘56E2FAE376A47F1C0961D722326B8423’;

4、使用 redis-cli 连接 redis 服务器,查看会显示有 “56E2FAE376A47F1C0961D722326B8423” key的 session 数据,value为序列化数据。

最新文章

  1. imx6 matrix keyboard
  2. CleanBlog(个人博客+源码)
  3. oracle数据匹配merge into
  4. JSON value
  5. 看css发现一个pointer-events:none;的东西
  6. mysql SQL_CALC_FOUND_ROWS
  7. HTML常用标签及其全称
  8. [转] Node.js 服务端实践之 GraphQL 初探
  9. Redis slowlog
  10. iOS开发之UITableView中计时器的几种实现方式(NSTimer、DispatchSource、CADisplayLink)
  11. html5之表格元素
  12. [ SSH框架 ] Spring框架学习之三(AOP开发和注解的使用)
  13. django基础 -- 8.cookie 和 session
  14. jdbc链接数据库的url两种写法
  15. windows环境下 curl 安装和使用
  16. android 实现一个简单纯文本的ListView
  17. yum源安装php报错缺少libmcrypt.so.4()(64bit)库
  18. CentOS7更改Docker默认镜像和容器存储位置
  19. net负载均衡服务器架构网址
  20. Asynchronous programming with Tornado

热门文章

  1. 移动端底部input被弹出的键盘遮挡
  2. Android--绑定服务调用服务的方法
  3. IOS_DatePicker_PickerView_SegmentControl_键盘处理
  4. Linux/ visual studio 编译使用Poco
  5. Android实战简易教程-第二十三枪(基于Baas的用户注冊和登录模块实现!)
  6. 兔子-svnserver,client搭建
  7. 【每日Scrum】第二天(4.12) TD学生助手Sprint1站立会议
  8. BUCK电路工作原理
  9. javascript 高级编程系列 - 继承
  10. caffe2--Install