0
0
Djangoframework~10 mins

Nginx as reverse proxy in Django - Interactive Code Practice

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

Complete the code to specify the port Nginx listens on.

Django
server {
    listen [1];
    location / {
        proxy_pass http://127.0.0.1:8000;
    }
}
Drag options to blanks, or click blank then click option'
A80
B443
C22
D8080
Attempts:
3 left
💡 Hint
Common Mistakes
Using port 443 without SSL configuration
Using SSH port 22 by mistake
2fill in blank
medium

Complete the code to set the proxy header for the original host.

Django
location / {
    proxy_set_header Host [1];
    proxy_pass http://127.0.0.1:8000;
}
Drag options to blanks, or click blank then click option'
A$remote_addr
B$host
C$http_user_agent
D$server_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using $remote_addr instead of $host
Using $server_name which is the server's own name
3fill in blank
hard

Fix the error in the proxy_pass URL to correctly forward requests to Django.

Django
location / {
    proxy_pass http://127.0.0.1[1]8000;
}
Drag options to blanks, or click blank then click option'
A:
B//
C/
D;
Attempts:
3 left
💡 Hint
Common Mistakes
Using slash instead of colon before port
Adding extra slashes causing malformed URL
4fill in blank
hard

Fill both blanks to set headers for real IP and forwarded protocol.

Django
location / {
    proxy_set_header X-Real-IP [1];
    proxy_set_header X-Forwarded-Proto [2];
    proxy_pass http://127.0.0.1:8000;
}
Drag options to blanks, or click blank then click option'
A$remote_addr
B$host
C$scheme
D$server_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using $host for X-Real-IP
Using $host instead of $scheme for X-Forwarded-Proto
5fill in blank
hard

Fill all three blanks to correctly configure proxy headers for Django behind Nginx.

Django
location / {
    proxy_set_header Host [1];
    proxy_set_header X-Real-IP [2];
    proxy_set_header X-Forwarded-For [3];
    proxy_pass http://127.0.0.1:8000;
}
Drag options to blanks, or click blank then click option'
A$host
B$remote_addr
C$proxy_add_x_forwarded_for
D$server_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using $server_name instead of $host
Not using $proxy_add_x_forwarded_for for X-Forwarded-For