Web / NGINX Interview questions
What is the difference between proxy_pass and rewrite in NGINX?
proxy_pass and rewrite solve different problems, even though both can change where a request ends up.
proxy_pass forwards a request to a different server entirely - the URL the client sees stays the same, but NGINX acts as an intermediary passing the request to an upstream application, which returns a response NGINX relays back.
location /api/ { proxy_pass http://backend_app; } location /old-path/ { rewrite ^/old-path/(.*)$ /new-path/$1 permanent; }
rewrite, by contrast, modifies the request URI itself, either internally (continuing processing with the new URI) or by issuing an HTTP redirect back to the client. It doesn't involve a backend server at all - it's pure URL manipulation within NGINX.
Confusing the two is a common mistake: using rewrite when you actually need to forward to another service, or using proxy_pass when you just need to change a URL path.
More Related questions...