Consider an Express app running on port 3000. Nginx is configured to forward requests from port 80 to this app. What is the visible effect when a user accesses the server's IP on port 80?
server {
listen 80;
location / {
proxy_pass http://localhost:3000;
}
}Think about what a reverse proxy does with incoming requests.
Nginx forwards requests from port 80 to the Express app on port 3000, so the user sees the app response transparently.
Which Nginx configuration snippet correctly forwards all requests to an Express app running on localhost port 4000?
Remember the full URL format for proxy_pass.
The proxy_pass directive requires a full URL including the protocol (http://) and hostname with port.
An Express app behind Nginx reverse proxy logs the client IP as 127.0.0.1 instead of the real user IP. What is the cause?
Think about how proxies pass client IP information.
Nginx must forward the original client IP using headers like X-Forwarded-For. Without this, Express sees the proxy's IP (localhost).
Nginx terminates HTTPS and proxies requests to Express over HTTP. In Express, what is the value of req.protocol by default?
Consider what Express actually receives from Nginx.
Express sees the protocol of the direct connection, which is HTTP from Nginx, so req.protocol is "http" unless trust proxy is enabled.
You want to set secure cookies in Express behind Nginx reverse proxy that terminates HTTPS. Which Express setting ensures cookies are marked secure correctly?
Think about how Express determines if a request is secure behind a proxy.
Setting app.set('trust proxy', 1) tells Express to trust the first proxy and use forwarded headers to detect HTTPS, enabling secure cookies.