zoukankan      html  css  js  c++  java
  • Nginx解决服务器宕机问题

    1.Nginx解决服务器宕机问题,Nginx配置服务器宕机策略,如果服务器宕机,会找下一台机器进行访问
    配置nginx.cfg配置文件,在映射拦截地址中加入代理地址响应方案
    location / {
    proxy_connect_timeout 1;
    proxy_send_timeout 1;
    proxy_read_timeout 1;
    proxy_pass http://backserver;
    index index.html index.htm;
    }


    2.解决网站跨域问题
    Nginx解决跨域问题,实现方案:
    www.a.com:8080/a
    www.b.com:8081/b

    如果在b工程的页面直接发送ajax请求a时会发生跨域问题,那么解决方案为:将A和B同时代理到Nginx,由Nginx做请求路由,直接在B工程页面中直接访问Nginx即可
    server {
    listen 80;
    server_name www.wdksoft.com;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location /a {
    #proxy_connect_timeout 1;
    #proxy_send_timeout 1;
    #proxy_read_timeout 1;
    proxy_pass http://www.a.com:8080/a/;
    index index.html index.htm;

    }
    location /b {
    #proxy_connect_timeout 1;
    #proxy_send_timeout 1;
    #proxy_read_timeout 1;
    proxy_pass http://www.b.com:8081/b/;
    index index.html index.htm;
    }
    }

    B页面请求:
    $("#button").click(function () {
    $.ajax({
    url:"http://www.wdksoft.com/a/AServlet?username="+$("#username").val(),
    type:"GET",
    success:function (result) {
    alert(result);
    }
    })
    });



    3.Nginx配置防盗链
    利用Nginx进行来源地址拦截,只要来源地址符合原资源地址,则可以访问,否则返回4.3状态码
    server {
    listen 80;
    server_name fdl.wdksoft.com;

    #charset koi8-r;

    #access_log logs/host.access.log main;
    #拦截所有关于jpg|jpeg|JPG|png|gif|icon格式的请求
    location ~ .*.(jpg|jpeg|JPG|png|gif|icon)$ {
    #验证blocked来源地址不为空并且符合referers配置的地址
    #none允许来源地址为空
    valid_referers blocked http://fdl.wdksoft.com/a fdl.wdksoft.com/a;
    #如果不符合则会return 403
    if ($invalid_referer) {
    rewrite ^/ http://www.a.com:8080/a/img/zysx.png;
    #return 403;
    }
    }
    location /a {
    proxy_pass http://www.a.com:8080/a/;
    index index.html index.htm;

    }

    }



    4.Nginx防止DDOS流量攻击
    DDOS流量攻击:频繁的发送请求,造成宽带占用,其他客户端无法访问

    Nginx解决DDOS流量攻击,利用limit_req_zone限制请求次数 limit_conn_zone限制连接次数

    #限制IP的每秒请求次数
    limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
    #限制同一个IP同一时间内创建连接次数
    limit_conn_zone $binary_remote_addr zone=addr:10m;
    server {
    listen 80;
    server_name ddos.wdksoft.com;

    location /a {
    limit_conn addr 1; #同一时间内只能建立一次连接
    limit_req zone=one;
    proxy_pass http://www.a.com:8080/a/;
    index index.html index.htm;

    }

    }

  • 相关阅读:
    查看pip install *.whl 支持的文件版本
    spark Infinate 的处理
    nc 文件的nan识别
    mysql 存中文失败问题
    tensorflow 安装
    数据库存含中文的json 时避免存成中文的ascii
    python 继承中的__init__
    python mysql数据库中 json的存储
    python 版本配置问题
    python dict 实现swich
  • 原文地址:https://www.cnblogs.com/danxun/p/12292225.html
Copyright © 2011-2022 走看看