Skip to Content
Nginx HTTP Server - Fourth Edition
book

Nginx HTTP Server - Fourth Edition

by Martin Bjerretoft Fjordvald, Nedelcu
February 2018
Beginner to intermediate
348 pages
9h 40m
English
Packt Publishing
Content preview from Nginx HTTP Server - Fourth Edition

Unexpected behavior

The if block should ideally be employed for simple situations, as its behavior might be surprising in some cases. Apart from the fact that if statements cannot be nested, the following situations may present issues:

# Two consecutive statements with the same condition: 
location / { 
    if ($uri = "/test.html") { 
       add_header X-Test-1 1; 
       expires 7; 
    } 
    if ($uri = "/test.html") { 
       add_header X-Test-1 1; 
    } 
} 

In this case, the first if block is ignored and only the second one is processed. However, if you insert a Rewrite module directive in the first block, such as rewrite, break, or return, the first block will be processed and the second one will be ignored.

There are many other cases where the use of if causes problems:

  • Having ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Nginx: From Beginner to Pro

Nginx: From Beginner to Pro

Rahul Soni
Nginx Essentials

Nginx Essentials

Valery Kholodkov, Valery I Kholodkov
SSH, The Secure Shell: The Definitive Guide, 2nd Edition

SSH, The Secure Shell: The Definitive Guide, 2nd Edition

Daniel J. Barrett, Richard E. Silverman, Robert G. Byrnes

Publisher Resources

ISBN: 9781788623551Other