0
0
Nginxdevops~5 mins

Adding response headers (add_header) in Nginx - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the add_header directive do in nginx?
It adds custom HTTP response headers to the responses sent by the nginx server to clients.
Click to reveal answer
beginner
How do you add a header named X-Frame-Options with value DENY in nginx?
Use the directive: <br>add_header X-Frame-Options "DENY";
Click to reveal answer
intermediate
Where in the nginx configuration file can you place the add_header directive?
You can place it inside http, server, or location blocks depending on the scope you want the header to apply.
Click to reveal answer
intermediate
What happens if you use add_header inside a location block that overrides a header set in server block?
The header set in the location block will override or add to the headers from the server block for requests matching that location.
Click to reveal answer
beginner
Why might you want to add security headers like Content-Security-Policy using add_header?
To improve security by controlling what resources the browser can load, preventing attacks like cross-site scripting (XSS).
Click to reveal answer
Which nginx directive is used to add a custom response header?
Aadd_header
Bset_header
Cheader_add
Dresponse_header
Where can the add_header directive be placed in nginx config?
AOnly inside <code>server</code> block
BOnly inside <code>http</code> block
CInside <code>http</code>, <code>server</code>, or <code>location</code> blocks
DOnly inside <code>location</code> block
What is the effect of adding add_header X-Frame-Options "DENY";?
AAllows the page to be framed by any site
BRedirects the page to another URL
CEnables caching of the page
DPrevents the page from being displayed in a frame or iframe
If you want to add a header only for a specific URL path, where should you put the add_header directive?
AInside <code>location</code> block for that path
BInside <code>server</code> block
CIn a separate config file
DInside <code>http</code> block
What must you do after changing nginx config to apply new headers?
ANothing, changes apply automatically
BRestart or reload nginx
CClear browser cache
DReinstall nginx
Explain how to add a custom HTTP response header in nginx and where you can place the directive.
Think about the scope of configuration blocks and the directive syntax.
You got /4 concepts.
    Describe why adding security headers with add_header is important and give an example.
    Consider how browsers use headers to control page behavior.
    You got /4 concepts.