首页 技术 正文
技术 2022年11月6日
0 收藏 480 点赞 537 浏览 1816 个字

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;

}

}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903