


How to configure Nginx page jump according to different browser languages
Simplified and Traditional Chinese Judgment
I want to decide whether to provide simplified or traditional Chinese files based on the accept-language in the http header. In chrome, chrome://settings/languages can set the preferred language, and the browser will set the accept-language header accordingly. A better way to handle it is to parse the field, obtain the qvalue, and select the most appropriate language based on priority. But it is only used to support Simplified and Traditional Chinese. I want to use a trick: ignore the priority, and as long as the words zh-hant, zh-tw, zh-hk and other words appear in accept-language, return to Traditional Chinese, otherwise return to Simplified Chinese.
map $http_accept_language $lang { default zhs; ~zh-hant zht; ~zh-tw zht; ~zh-hk zht; }
I use hexo to generate the website, and the source files are written in traditional Chinese. For the 2015-10-06-nginx-accept-language-zhs-zht.html generated by hexo generate, use opencc to convert it to the simplified version: 2015-10-06-nginx-accept-language-zhs-zht.html.zhs .html. Depending on the situation, some other files need to be converted, such as atom.xml and popular.json that provide the "most read articles" function.
# zsh cd ~/maskray.me/public opencc -c t2s.json -i atom.xml -o atom.xml.zhs.xml for i in **/*.html 20*; do # 选择需要简繁体支持的文件 c=${#${(s/.html/%)i}//[^%]/} # 计算子串`.html`出现次数 if (( $c <= 1 )); then # 出现一次的为原始文件,需要转换成简体 opencc -c t2s.json -i $i -o $i.zhs.html fi done
Specify routes that require simplified and traditional Chinese support in the nginx configuration file:
location ~ ^/blog/20?? { try_files $uri.$lang.html $uri =404; add_header vary accept-language; } location ~ /atom.xml { try_files $uri.$lang.xml $uri =404; add_header vary accept-language; } location ~ \.json$ { try_files $uri.$lang.json $uri =404; add_header vary accept-language; } # 其他需要简繁体支持的路由
Forward to different pages based on the accept-language in the http request header:
Go directly to the code
if ($http_accept_language ~* ^zh){ set $lang "/index_cn.jsp"; } if ($http_accept_language !~* ^zh){ set $lang "/index_en.jsp"; } location =/ { proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $remote_addr; proxy_pass http://localhost:8080$lang; }
Test:
http://www.findmaven.net is a search engine for findjar and findmaven
Browser settings (English)
The above is the detailed content of How to configure Nginx page jump according to different browser languages. For more information, please follow other related articles on the PHP Chinese website!

NGINX is suitable for handling high concurrency and static content, while Apache is suitable for dynamic content and complex URL rewrites. 1.NGINX adopts an event-driven model, suitable for high concurrency. 2. Apache uses process or thread model, which is suitable for dynamic content. 3. NGINX configuration is simple, Apache configuration is complex but more flexible.

NGINX and Apache each have their own advantages, and the choice depends on the specific needs. 1.NGINX is suitable for high concurrency, with simple deployment, and configuration examples include virtual hosts and reverse proxy. 2. Apache is suitable for complex configurations and is equally simple to deploy. Configuration examples include virtual hosts and URL rewrites.

The purpose of NGINXUnit is to simplify the deployment and management of web applications. Its advantages include: 1) Supports multiple programming languages, such as Python, PHP, Go, Java and Node.js; 2) Provides dynamic configuration and automatic reloading functions; 3) manages application lifecycle through a unified API; 4) Adopt an asynchronous I/O model to support high concurrency and load balancing.

NGINX started in 2002 and was developed by IgorSysoev to solve the C10k problem. 1.NGINX is a high-performance web server, an event-driven asynchronous architecture, suitable for high concurrency. 2. Provide advanced functions such as reverse proxy, load balancing and caching to improve system performance and reliability. 3. Optimization techniques include adjusting the number of worker processes, enabling Gzip compression, using HTTP/2 and security configuration.

The main architecture difference between NGINX and Apache is that NGINX adopts event-driven, asynchronous non-blocking model, while Apache uses process or thread model. 1) NGINX efficiently handles high-concurrent connections through event loops and I/O multiplexing mechanisms, suitable for static content and reverse proxy. 2) Apache adopts a multi-process or multi-threaded model, which is highly stable but has high resource consumption, and is suitable for scenarios where rich module expansion is required.

NGINX is suitable for handling high concurrent and static content, while Apache is suitable for complex configurations and dynamic content. 1. NGINX efficiently handles concurrent connections, suitable for high-traffic scenarios, but requires additional configuration when processing dynamic content. 2. Apache provides rich modules and flexible configurations, which are suitable for complex needs, but have poor high concurrency performance.

NGINX and Apache each have their own advantages and disadvantages, and the choice should be based on specific needs. 1.NGINX is suitable for high concurrency scenarios because of its asynchronous non-blocking architecture. 2. Apache is suitable for low-concurrency scenarios that require complex configurations, because of its modular design.

NGINXUnit is an open source application server that supports multiple programming languages and provides functions such as dynamic configuration, zero downtime updates and built-in load balancing. 1. Dynamic configuration: You can modify the configuration without restarting. 2. Multilingual support: compatible with Python, Go, Java, PHP, etc. 3. Zero downtime update: Supports application updates that do not interrupt services. 4. Built-in load balancing: Requests can be distributed to multiple application instances.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
