0
0
Nginxdevops~10 mins

server_name directive in Nginx - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the server name to example.com.

Nginx
server_name [1];
Drag options to blanks, or click blank then click option'
Aexample.com
Blocalhost
Cdefault_server
D_
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'localhost' instead of the actual domain name.
Using 'default_server' which is not a valid server_name.
2fill in blank
medium

Complete the code to set the server to respond to both www.example.com and example.com.

Nginx
server_name [1];
Drag options to blanks, or click blank then click option'
A_
Bexample.com
Cwww.example.com
Dexample.com www.example.com
Attempts:
3 left
💡 Hint
Common Mistakes
Listing only one domain name.
Using commas instead of spaces.
3fill in blank
hard

Fix the error in the server_name directive to correctly match all subdomains of example.com.

Nginx
server_name [1];
Drag options to blanks, or click blank then click option'
A*.example.com
Bexample.*
Cexample.com*
Dwww.*.com
Attempts:
3 left
💡 Hint
Common Mistakes
Placing the wildcard after the domain name.
Using wildcards in the middle of the domain.
4fill in blank
hard

Fill both blanks to set the server to respond to example.com and redirect www.example.com to it.

Nginx
server_name [1];
if ($host = [2]) {
    return 301 https://example.com$request_uri;
}
Drag options to blanks, or click blank then click option'
Aexample.com
Bwww.example.com
Clocalhost
D_
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the domain names in the blanks.
Using localhost instead of the actual domain.
5fill in blank
hard

Fill all three blanks to create a server block that listens on port 80, sets server_name to example.com and www.example.com, and redirects all HTTP requests to HTTPS.

Nginx
server {
    listen [1];
    server_name [2];
    return [3] https://$host$request_uri;
}
Drag options to blanks, or click blank then click option'
A80
Bexample.com www.example.com
C301
D443
Attempts:
3 left
💡 Hint
Common Mistakes
Using port 443 for listening in this block.
Using 302 instead of 301 for redirect.
Not listing both domain names in server_name.