0
0
Nginxdevops~5 mins

IP hash for session persistence in Nginx - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of using ip_hash in nginx?
The ip_hash directive in nginx ensures that requests from the same client IP address are always sent to the same backend server. This helps keep user sessions consistent.
Click to reveal answer
intermediate
How does ip_hash differ from round-robin load balancing?
Round-robin sends requests to backend servers in order, cycling through them. ip_hash sends requests from the same IP to the same server, maintaining session persistence.
Click to reveal answer
beginner
Show a simple nginx configuration snippet using ip_hash.
upstream backend { ip_hash; server backend1.example.com; server backend2.example.com; } server { location / { proxy_pass http://backend; } }
Click to reveal answer
intermediate
What happens if a client IP changes when using ip_hash?
If the client IP changes, nginx may route the request to a different backend server, potentially breaking session persistence.
Click to reveal answer
intermediate
Can ip_hash be used with SSL termination in nginx?
Yes, ip_hash works with SSL termination. The load balancer handles SSL and then uses ip_hash to route requests to backend servers.
Click to reveal answer
What does the ip_hash directive do in nginx?
AEncrypts client IP addresses
BDistributes requests randomly to backend servers
CBlocks requests from unknown IPs
DRoutes requests from the same IP to the same backend server
Which load balancing method does ip_hash replace or complement?
ARound-robin
BLeast connections
CRandom
DWeighted
What is a limitation of using ip_hash for session persistence?
AIt requires sticky cookies
BIt only works with HTTP/2
CIt depends on client IP, which can change
DIt disables SSL
How do you enable ip_hash in an nginx upstream block?
AAdd <code>ip_hash;</code> inside the upstream block
BAdd <code>ip_hash on;</code> in the server block
CSet <code>proxy_pass ip_hash;</code>
DUse <code>sticky_ip;</code> directive
If a user behind a proxy shares the same IP with others, what is a possible effect when using ip_hash?
AUsers get distributed evenly
BAll users share the same backend server
CSessions are encrypted
DRequests are blocked
Explain how ip_hash helps maintain session persistence in nginx load balancing.
Think about how nginx decides where to send requests from the same user.
You got /4 concepts.
    Describe a scenario where using ip_hash might cause problems and why.
    Consider what happens if the IP address is not stable or shared by many users.
    You got /4 concepts.