Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to solve the problems encountered in nginx+uWsgi configuration

Shulou Source: shulou.com Published: 2022-06-01 16:10:09 10月03日 Update

Editor to share with you how to solve the problems encountered in nginx+uWsgi configuration, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

UWSGI is a deployment choice on servers like nginx, lighttpd, and cherokee. For more options, see FastCGI and stand-alone WSGI containers. You will first need a uWSGI server to use your WSGI application using the uWSGI protocol. UWSGI is not only a protocol, but also an application server that provides uWSGI, FastCGI, and HTTP protocols.

1. Redirect the response of the uwsgi server whose response code is greater than or equal to 300to nginx for processing using the error_page instruction

Uwsgi_intercept_errors on

2. Nginx simple filter crawler

# prohibit crawling if of crawler tools ($http_user_agent ~ * "python | curl | java | wget | httpclient | okhttp | Scrapy") {return 503;} # prohibit access to if ($http_user_agent ~ "WinHttp | WebZIP | node-superagent | java/ | Jullo | JikeSpider | Indy Library | Alexa Toolbar | AskTbFXTV | CrawlDaddy | Java | Feedly | Apache-HttpAsyncClient | ApacheBench | Microsoft URL Control | ZmEu | oBot | jaunty | oBot | jaunty | Python-urllib | | Python-urllib | lightDeckReports Bot | Python-urllib | Python-urllib | jaunty | Python-urllib | jaunty | Python-urllib | lightDeckReports Bot | lightDeckReports Bot | Python-urllib | Python-urllib | jaunty | Python-urllib | jaunty | jaunty | Python-urllib | Python-urllib |

3. Http request is redirected to https

# http jumps to httpsset $flag 0bot 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. Reset the error page status code to 200 and return the specified content

Error_page 502404405500 / error;#error had better not have a suffix. Write an error.html before, and then want to return it to json. As a result, various settings do not work. Later, after working for a long time, we found that the pot location / error {default_type application/json; # add_header name value always;#always is an optional parameter. If this header already exists, it will not overwrite add_header Access-Control-Allow-Origin *. Return 200' {"code": 0, "msg": "your request cannot be processed temporarily", "more": $status}';} these are all the contents of the article "how to solve the problems encountered in nginx+uWsgi configuration". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Servers services content articles questions configurations suffixes more crawlers processing applications selections not much code functions parameters most containers tools situations Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi NVidia MySQL Apple Huawei