In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How do I configure the return text in nginx? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Fixed text:
Location ~ ^ / get_text {default_type text/html; return 200' This is textbooks;}
Fixed json:
Location ~ ^ / get_json {default_type application/json; return 200'{"status": "success", "result": "nginx json"}';}
After saving, reloading the configuration will take effect. Note: default_type must be added, otherwise the browser will download it as an unrecognized file.
Alternatively, you can simply return different strings based on the requested URL, as shown below:
Location ~ ^ / get_text/article/ (. *) _ (\ d +). Html$ {default_type text/html; set $s $1; set $d $2; return 200 str:$s$d;}
In this way, you can simply intercept the strings in url, of course, you can also use (. *) to match all of them. In practice, you can define them according to different requirements.
The above are some simple examples. For simple processing in a server environment, making full use of nginx can save some programming work.
In addition, I would like to add the problem of Chinese display, because utf-8 character encoding is used under Linux, by default, our browser will render the page with GBK encoding when the server does not specify the encoding or the static page does not declare the encoding. If the browser returns Chinese by default, the browser uses gbk to parse the utf-8 code, obviously garbled. At this point, you need to actively add header to the nginx location block to output the correct encoding, adding the following content: add_header Content-Type 'text/html Charset=utf-8'; so that the browser knows which code we are using, as shown in the following figure:
Or it is possible to change the add_header line to charset utf-8;.
After reading the above, have you mastered how to configure the returned text in nginx? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.