0
0
Expressframework~10 mins

Nginx as reverse proxy in Express - Interactive Code Practice

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

Complete the code to create a basic Express server that listens on port 3000.

Express
const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.send('Hello from Express!');
});

app.listen([1], () => {
  console.log('Server running');
});
Drag options to blanks, or click blank then click option'
A5000
B8080
C80
D3000
Attempts:
3 left
💡 Hint
Common Mistakes
Using port 80 directly in Express without root permissions.
Choosing a port number that conflicts with other services.
2fill in blank
medium

Complete the Nginx configuration line to set the proxy pass URL to the Express server running on localhost port 3000.

Express
location / {
    proxy_pass http://[1];
}
Drag options to blanks, or click blank then click option'
A127.0.0.1:8080
Blocalhost:3000
C0.0.0.0:3000
Dlocalhost:80
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong port numbers in proxy_pass.
Using IP 0.0.0.0 which is not routable.
3fill in blank
hard

Fix the error in the Nginx proxy configuration to correctly forward headers.

Express
location /api/ {
    proxy_pass http://localhost:3000/;
    proxy_set_header Host [1];
}
Drag options to blanks, or click blank then click option'
A$host
B$http_host
C$remote_addr
D$server_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using $remote_addr which is the client IP, not host.
Using $server_name which is the Nginx server name, not the request host.
4fill in blank
hard

Fill both blanks to complete the Nginx configuration that forwards requests and sets headers for proxying.

Express
location /app/ {
    proxy_pass http://localhost:[1]/;
    proxy_set_header X-Real-IP [2];
}
Drag options to blanks, or click blank then click option'
A3000
B$remote_addr
C$host
D8080
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong port number in proxy_pass.
Setting X-Real-IP to $host instead of $remote_addr.
5fill in blank
hard

Fill in the blanks to complete the Express middleware that trusts the proxy and logs the real client IP.

Express
const express = require('express');
const app = express();

app.set('[1]', true);

app.use((req, res, next) => {
  console.log('Client IP:', req.[2]);
  next();
});
Drag options to blanks, or click blank then click option'
Atrust proxy
Bconnection
Cip
Dsocket
Attempts:
3 left
💡 Hint
Common Mistakes
Not setting 'trust proxy' causes Express to see proxy IP.
Using incorrect property names to get client IP.