What is the purpose of the proxy_pass directive in nginx?
The proxy_pass directive tells nginx to forward client requests to another server or service, acting as a middleman to pass requests and responses.
Click to reveal answer
beginner
How do you use proxy_pass to forward requests to http://localhost:8080?
Inside an nginx location block, write:
proxy_pass http://localhost:8080;
This sends matching requests to the server running on port 8080 on the same machine.
Click to reveal answer
intermediate
What happens if you omit the trailing slash in proxy_pass URL?
If the URL in proxy_pass does not end with a slash, nginx replaces the matching part of the request URI with the URL path. This can change the request path sent to the backend.
Click to reveal answer
beginner
Can proxy_pass be used to forward requests to an HTTPS backend?
Yes, you can use proxy_pass https://backend-server; to forward requests securely to an HTTPS backend server.
Click to reveal answer
intermediate
What directive is commonly used with proxy_pass to set the original host header?
The directive proxy_set_header Host $host; is often used with proxy_pass to pass the original host header to the backend server.
Click to reveal answer
What does the proxy_pass directive do in nginx?
AForwards client requests to another server
BBlocks client requests
CCaches static files
DStarts the nginx server
✗ Incorrect
proxy_pass forwards requests to another server or service, acting as a reverse proxy.
Which of the following is a correct proxy_pass usage to forward to http://example.com?
Aproxy_pass http://example.com;
Bproxy_pass example.com;
Cproxy_pass https://example.com
Dproxy_pass //example.com;
✗ Incorrect
The URL must include the scheme like http:// or https://.
What is the effect of adding a trailing slash to the URL in proxy_pass?
AIt disables proxying
BIt changes how the request URI is forwarded
CIt enables caching
DIt restarts nginx
✗ Incorrect
A trailing slash changes how nginx modifies the request URI when forwarding.
Can proxy_pass forward requests to an HTTPS backend?
AOnly if SSL is disabled
BNo, only HTTP backends are supported
CYes, by specifying <code>https://</code> in the URL
DOnly with extra modules
✗ Incorrect
Using https:// in the proxy_pass URL forwards requests securely.
Which directive is used to pass the original host header to the backend when using proxy_pass?
Aproxy_cache on;
Bproxy_redirect off;
Cproxy_buffering off;
Dproxy_set_header Host $host;
✗ Incorrect
proxy_set_header Host $host; passes the original host header to the backend server.
Explain how the proxy_pass directive works in nginx and why it is useful.
Think about nginx acting like a middleman between clients and backend servers.
You got /4 concepts.
Describe the difference in behavior when using a trailing slash versus no trailing slash in the proxy_pass URL.
Focus on how nginx changes the request path sent to the backend.
You got /4 concepts.
Practice
(1/5)
1. What is the primary purpose of the proxy_pass directive in an Nginx configuration?
easy
A. To block incoming requests based on IP address
B. To serve static files directly from Nginx
C. To forward client requests to another server
D. To rewrite URLs within the same server
Solution
Step 1: Understand the role of proxy_pass
The proxy_pass directive is used to send client requests received by Nginx to another server, often called a backend or upstream server.
Step 2: Compare with other options
Serving static files is done by root or alias, blocking IPs uses deny, and URL rewriting uses rewrite. These are different from proxy_pass.
Final Answer:
To forward client requests to another server -> Option C
Quick Check:
proxy_pass forwards requests [OK]
Hint: Remember: proxy_pass sends requests to another server [OK]
Common Mistakes:
Confusing proxy_pass with static file serving
Thinking proxy_pass blocks requests
Mixing proxy_pass with URL rewriting
2. Which of the following is the correct syntax to forward all requests from /app/ to http://backend.local/ using proxy_pass inside a location /app/ block?
easy
A. proxy_pass http://backend.local/;
B. proxy_pass http://backend.local/app/;
C. proxy_pass backend.local;
D. proxy_pass http://backend.local
Solution
Step 1: Understand proxy_pass URL format
The URL in proxy_pass must include the scheme (http://) and a trailing slash if you want to replace the matching part of the request URI.
Step 2: Analyze options
proxy_pass http://backend.local/; uses http://backend.local/ with trailing slash, which correctly forwards requests replacing /app/ with /. proxy_pass http://backend.local/app/; appends /app/ again, causing duplication. proxy_pass backend.local; lacks scheme, invalid syntax. proxy_pass http://backend.local misses trailing slash, causing different URI handling.
Final Answer:
proxy_pass http://backend.local/; -> Option A
Quick Check:
Correct proxy_pass URL includes scheme and trailing slash [OK]
Hint: Always include scheme and trailing slash for correct URI mapping [OK]
Clients report 404 errors from backend for requests like /service/data. What is the likely cause?
medium
A. proxy_pass URL duplicates the /service/ path causing wrong backend URI
B. Missing trailing slash in proxy_pass URL
C. Backend server is down
D. Nginx location block syntax error
Solution
Step 1: Analyze proxy_pass with matching location
When proxy_pass URL includes the same path as location, Nginx appends the full request URI after it, causing duplication.
Step 2: Understand effect on backend URI
Request /service/data becomes /service/service/data at backend, likely causing 404 errors.
Final Answer:
proxy_pass URL duplicates the /service/ path causing wrong backend URI -> Option A
Quick Check:
Duplicated path in proxy_pass causes 404 [OK]
Hint: Avoid repeating location path in proxy_pass URL [OK]
Common Mistakes:
Ignoring duplicated path in proxy_pass
Assuming backend down without checking URI
Confusing missing slash with duplicated path
5. You want to forward requests from /app/ to http://backend.local/ but keep the original /app/ prefix in the proxied URI. Which proxy_pass configuration achieves this?
hard
A. proxy_pass http://backend.local/;
B. proxy_pass http://backend.local/app/
C. proxy_pass http://backend.local/app;
D. proxy_pass http://backend.local;
Solution
Step 1: Understand proxy_pass without trailing slash
If proxy_pass URL has no trailing slash, Nginx appends the full original request URI after the host.
Step 2: Apply to example
Using proxy_pass http://backend.local; inside location /app/ sends requests like /app/data as http://backend.local/app/data, preserving the prefix.
Final Answer:
proxy_pass http://backend.local; -> Option D
Quick Check:
No trailing slash keeps original URI prefix [OK]
Hint: No trailing slash keeps full original URI [OK]
Common Mistakes:
Adding trailing slash removes original prefix
Appending /app/ twice causing duplication
Missing scheme in proxy_pass URL
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.