Skip to content
Foxipa
Code Completion 5 Challenges

Complete the config: Nginx Layer 4 Routing

Fill in stream blocks, PROXY protocol, and SNI-based passthrough.

Advanced ~4 min read

Challenge 1

Open the layer-4 configuration context.

nginx Your answer
 {
    upstream pg { server 10.0.0.5:5432; }
}

Press Ctrl⌘Enter to check your answer

Challenge 2

Accept the PROXY protocol on the backend listener (stream context).

nginx Your answer
server {
    listen 5432 ;
    proxy_pass pg;
}

Press Ctrl⌘Enter to check your answer

Challenge 3

Peek at the ClientHello without terminating TLS.

nginx Your answer
server {
    listen 443;
     on;
    proxy_pass $backend;
}

Press Ctrl⌘Enter to check your answer

Challenge 4

Route by the peeked SNI hostname.

nginx Your answer
map $ssl_preread_server_name $backend {
    api.example.com  api_pool;
    default          ;
}

Press Ctrl⌘Enter to check your answer

Challenge 5

Proxy a UDP service.

nginx Your answer
server {
    listen 53 ;
    proxy_pass dns_backend;
}

Press Ctrl⌘Enter to check your answer