I need guidance on how to set up Nginx to serve static files while also working with the App Engine development server on my local machine. The idea is to have Nginx serve all static resources directly, while directing other requests to the dev server.
Here’s my intended setup:
Dynamic requests:
http://localhost -> nginx -> dev_appserver
Static file requests:
http://localhost/static/css (js, images, etc.) -> nginx (serving those files directly)
Both services are hosted locally. Can anyone provide insights into the necessary Nginx configurations to achieve this?
That config works great, but App Engine has a few extra gotchas. The dev server runs on port 8080 by default, so make sure your proxy handles headers properly. I’d add proxy_set_header Host $host;
and proxy_set_header X-Real-IP $remote_addr;
to your proxy block - keeps the request context intact. For static files, throw in some cache headers with the expires
directive in your static location block. Performance boost during dev work. Oh, and watch your location block order - put specific paths before general ones or you’ll get weird matching issues.
u can use location blocks in nginx.conf. try location /static/ { root /path/to/static; }
for static files and location / { proxy_pass http://localhost:8080; }
for dynamic ones. just make sure the static comes first, gives it top priority.
Interesting setup! Any issues with hot reloading when nginx is in front of your dev server? I’m curious about websocket connections in this config - does App Engine’s auto-refresh still work smoothly during development?