Skip to content

Commit 680c074

Browse files
committed
Merge pull request openresty#8 from robbyt/patch-1
several text edits
2 parents ef631be + 5726014 commit 680c074

File tree

1 file changed

+22
-28
lines changed

1 file changed

+22
-28
lines changed

en/02-NginxDirectiveExecOrder01.tut

+22-28
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
= Nginx directive execution order (01) =
22

3-
It can be really frustrated for many Nginx users, that
4-
if multiple Nginx module's commands are written within
5-
one C<location> directive, the execution order can be
6-
very different from the order they were written. For those
7-
impatient who choose "try out possibilities before everything
8-
else", the directive commands can be scattered like a hell.
9-
This series is to uncover the mysteries and help you better
10-
understand the execution ordering behind the scene.
3+
When there are multiple Nginx module commands in a
4+
C<location> directive, the execution order can be
5+
different from what you expect. Busy Nginx users who
6+
attempt to configure Nginx by "trial and error" may be
7+
very confused by this behavior. This series is to
8+
uncover the mysteries and help you better
9+
understand the execution ordering behind the scenes.
1110

1211
We start with a confused example:
1312

@@ -22,33 +21,31 @@ We start with a confused example:
2221

2322
Clearly, we'd expect to output C<32>, followed by C<56>. Because
2423
variable C<$a> has been reset after command L<ngx_echo/echo> "is
25-
executed". Really? you are welcomed to the reality:
24+
executed". Really? the reality is:
2625

2726
:bash
2827
$ curl 'http://localhost:8080/test
2928
56
3029
56
3130

3231
Wow, statement C<set $a 56> must have had been executed before
33-
the first C<echo $a> command, but why? Is it a Nginx bug ?
32+
the first C<echo $a> command, but why? Is it a Nginx bug?
3433

35-
There ain't any Nginx bug here, or we'd rather rephrase it as a
36-
feature, and it's a long story. When Nginx handles every request,
34+
No, this is not an Nginx bug. When Nginx handles every request,
3735
the execution follows a few predefined phases.
3836

3937
There can be altogether 11 phases when Nginx handles a request, let's
4038
start with three most common ones: C<rewrite>, C<access> and C<content>
41-
(later on the other phases will be addressed)
39+
(The other phases will be addressed later.)
4240

43-
Usually a Nginx module and its commands register their execution
41+
Usually an Nginx module and its commands register their execution
4442
in only one of those phases. For example command L<ngx_rewrite/set> runs
4543
in phase C<rewrite>, and command L<ngx_echo/echo> runs in phase C<content>.
4644
Since phase C<rewrite> occurs before phase C<content> for every request
4745
processing, its commands are executed earlier as well. Therefore,
4846
command L<ngx_rewrite/set> always gets executed before command L<ngx_echo/echo>
4947
within one C<location> directive, regardless of their statement ordering
50-
in the
51-
configuration.
48+
in the configuration.
5249

5350
Back to our example:
5451

@@ -69,19 +66,17 @@ The actual execution ordering is:
6966

7067
It's clear now, two commands L<ngx_rewrite/set> are executed in phase
7168
C<rewrite>, two commands L<ngx_echo/echo> are executed afterwards in
72-
phase C<content>. Commands belonging to different phases cannot be
73-
executed back and forth.
69+
phase C<content>. Commands in different phases cannot be executed
70+
back and forth.
7471

75-
To prove ourselves and better uncover these points, We can
76-
troubleshoot Nginx's "debug log".
72+
To prove this, we can enable Nginx's "debug log".
7773

78-
We've not checked Nginx "debug log" before, so let's briefly introduce
79-
its usage."debug log" by default is disabled, because it has very
80-
big runtime overheads and overall Nginx service is degraded. To enable
81-
"debug log" we would need to reconfigure and recompile Nginx binary, by
82-
giving C<--with-debug> option for the package's C<./configure> script.
83-
The typical steps are as following when build under Linux or Mac OS X
84-
from source:
74+
If you have not worked with Nginx "debug log" before, here is a brief
75+
introduction. The "debug log" is disabled by default because
76+
performance is degraded when it is enabled. To enable "debug log"
77+
you must reconfigure and recompile Nginx, and set the
78+
C<--with-debug> option for the package's C<./configure> script.
79+
When building under Linux or Mac OS X from source:
8580

8681
:bash
8782
tar xvf nginx-1.0.10.tar.gz
@@ -240,4 +235,3 @@ of
240235
execution ordering. Igor Sysoev, the author of Nginx, has made the statements
241236
a few times publicly, that Nginx mini language in its configuration is
242237
"declarative" not "procedural".
243-

0 commit comments

Comments
 (0)