uWSGI 是在像 nginx 、 lighttpd 以及 cherokee 服务器上的一个部署的选择。更多选择见 FastCGI 和 独立 WSGI 容器 。 你会首先需要一个 uWSGI 服务器来用 uWSGI 协议来使用你的 WSGI 应用。 uWSGI 是一个协议,同样也是一个应用服务器,可以提供 uWSGI 、FastCGI 和 HTTP 协议。
1、使uwsgi服务器响应代码大于或等于300的响应重定向到nginx以使用error_page指令进行处理
uwsgi_intercept_errors on;
2、nginx简单过滤爬虫
#禁止爬虫工具的抓取
if ($http_user_agent ——* "python|curl|java|wget|httpclient|okhttp|Scrapy") {
return 503;
}
#禁止指定UA及UA为空的访问
if ($http_user_agent —— "WinHttp|WebZIP|FetchURL|node-superagent|java/|FeedDemon|Jullo|JikeSpider|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|Java|Feedly|Apache-HttpAsyncClient|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|HttpClient|MJ12bot|heritrix|EasouSpider|Ezooms|BOT/0.1|YandexBot|FlightDeckReports|Linguee Bot|^$" ) {
return 403;
}
3、http请求重定向到https
#http跳转https
set $flag 0;
if ($host = "wxapp.zyqcn.cn") {
set $flag "${flag}1";
}
if ($scheme = "http") {
set $flag "${flag}2";
}
if ($flag = "012") {
rewrite ^(.*) https://$host$1 permanent;
}
4、将错误页状态码重设为200,并返回指定内容
error_page 502 404 405 500 =200 /error;
#error最好不要带后缀,之前写了个error.html,然后下面想返回成json,结果各种设置不起作用,后来搞了半天之后才发现是后缀的锅
location /error {
default_type application/json;
#add_header name value always;#always是可选参数,已经存在这个header的情况下使用不会覆盖
add_header Access-Control-Allow-Origin *;
return 200 '{"code": 0,"msg":"您的请求暂时无法处理","more": $status}';
}
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有