關于nginx+uWsgi配置遇到的問題的解決
uWSGI 是在像 nginx 、 lighttpd 以及 cherokee 服務器上的一個部署的選擇。更多選擇見 FastCGI 和 獨立 WSGI 容器 。 你會首先需要一個 uWSGI 服務器來用 uWSGI 協(xié)議來使用你的 WSGI 應用。 uWSGI 是一個協(xié)議,同樣也是一個應用服務器,可以提供 uWSGI 、FastCGI 和 HTTP 協(xié)議。
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跳轉(zhuǎn)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、將錯誤頁狀態(tài)碼重設為200,并返回指定內(nèi)容
error_page 502 404 405 500 =200 /error; #error最好不要帶后綴,之前寫了個error.html,然后下面想返回成json,結果各種設置不起作用,后來搞了半天之后才發(fā)現(xiàn)是后綴的鍋 location /error { default_type application/json; #add_header name value always;#always是可選參數(shù),已經(jīng)存在這個header的情況下使用不會覆蓋 add_header Access-Control-Allow-Origin *; return 200 '{"code": 0,"msg":"您的請求暫時無法處理","more": $status}'; }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Nginx隱藏式跳轉(zhuǎn)(瀏覽器URL跳轉(zhuǎn)后保持不變)
這篇文章主要介紹了Nginx隱藏式跳轉(zhuǎn)(瀏覽器URL跳轉(zhuǎn)后保持不變),需要的朋友可以參考下2022-04-04