File tree Expand file tree Collapse file tree 4 files changed +78
-0
lines changed Expand file tree Collapse file tree 4 files changed +78
-0
lines changed Original file line number Diff line number Diff line change 44- [ 更多nginx文档] ( https://weiliang-ms.github.io/nginx/ )
55- [ 更多linux相关文档] ( https://weiliang-ms.github.io/wl-awesome/ )
66
7+ > 解释说明
8+
9+ 1 . ` NGINX ` 中重写` url ` 的能力是一个非常强大和重要的特性,从技术角度讲` return ` 与` rewrite ` 均能实现。
10+ 但使用` return ` 相对` rewrite ` 更简单和更快,因为计算` RegEx ` 会产生额外的系统开销。
11+ 2 . ` Return ` 指令可以立即停止处理请求(它直接停止执行)并将指定的代码返回给客户端,省略了正则计算的流程。
12+ 3 . 如果你需要用` regex ` 验证` URL ` 或者需要获取原始` URL ` 中的元素(显然不在相应的` NGINX ` 变量中),那么你应该使用` rewrite `
13+
14+ > 使用样例
15+
16+ - 不建议实现方式
17+
18+ ``` nginx configuration
19+ server {
20+
21+ ...
22+
23+ location / {
24+
25+ try_files $uri $uri/ =404;
26+
27+ rewrite ^/(.*)$ https://example.com/$1 permanent;
28+
29+ }
30+
31+ ...
32+
33+ }
34+ ```
35+
36+ - 建议实现方式
37+
38+ ``` nginx configuration
39+ server {
40+
41+ ...
42+
43+ location / {
44+
45+ try_files $uri $uri/ =404;
46+
47+ return 301 https://example.com$request_uri;
48+
49+ }
50+
51+ ...
52+
53+ }
54+ ```
Original file line number Diff line number Diff line change 1+ ### 使用return代替rewrite做重定向
2+
3+ [ 原文地址] ( https://github.com/trimstray/nginx-admins-handbook/blob/master/doc/RULES.md#beginner-enable-pcre-jit-to-speed-up-processing-of-regular-expressions )
4+ - [ 更多nginx文档] ( https://weiliang-ms.github.io/nginx/ )
5+ - [ 更多linux相关文档] ( https://weiliang-ms.github.io/wl-awesome/ )
6+
7+ > 解释说明
8+
9+ 1 . 正则检查规则可能非常耗时,尤其是复杂的正则表达式(regex)条件,允许对正则表达式使用` JIT ` 可以加快处理速度。
10+ 2 . 通过使用` PCRE ` 库编译` NGINX ` ,可以用` location ` 块执行复杂的操作,并使用强大的` rewrite ` 指令
11+ 3 .
12+
13+ > 使用样例
14+
15+ - 不建议实现方式
16+
17+ ``` nginx configuration
18+ ```
19+
20+ - 建议实现方式
21+
22+ ``` nginx configuration
23+
24+ ```
Original file line number Diff line number Diff line change @@ -62,6 +62,11 @@ http {
6262 server_tokens off;
6363 more_set_headers "Server: Unknown" ;
6464 absolute_redirect off;
65+
66+ # pcre JIT
67+ pcre_jit on;
68+
69+ # compress
6570 gzip on;
6671 gzip_min_length 1k ;
6772 gzip_comp_level 1;
Original file line number Diff line number Diff line change @@ -108,6 +108,7 @@ set +e
108108 --with-threads \
109109 --with-openssl= %{opensslVersion } \
110110 --with-pcre= %{pcreVersion } \
111+ --with-pcre-jit \
111112 --with-zlib= %{zlibVersion } \
112113 --add-module= ngx_cache_purge-2.3 \
113114 --add-module= headers-more-nginx-module-master \
You can’t perform that action at this time.
0 commit comments