I’m looking to set up Nginx to serve static files while routing dynamic requests to my AppEngine development server. I want Nginx to handle all static file requests directly, while passing dynamic requests to the dev_appserver for processing.
Here’s the setup I’m aiming for:
- Requests to the main page should go to the dev_appserver via Nginx.
- Static resources like CSS, JavaScript, and images should be served directly by Nginx without involving the dev_appserver.
Both applications run on the same machine, and here’s the desired flow:
Dynamic content path:
http://localhost/app -> nginx -> dev_appserver
Static content path:
http://localhost/assets/style.css -> nginx (served directly)
http://localhost/assets/script.js -> nginx (served directly)
http://localhost/assets/logo.png -> nginx (served directly)
What Nginx configuration would I need to implement this?
This setup works great. Just make sure your static location block takes priority over the catch-all proxy location. Add try_files $uri =404; in your assets location - otherwise it’ll fall back to your app server when static files don’t exist. Throw in some caching headers like expires 1h; for better performance. Double-check that your root directive actually points to where your CSS, JS, and images live. Pro tip: don’t forget to reload Nginx after making changes. I’ve seen people scratch their heads over weird routing issues because they didn’t restart the service.
interesting setup! planning to use location blocks for routing? also curious why you’re choosing nginx over letting dev_appserver handle everything during developmnt. seems like extra complexity but maybe I’m missing something obvious 
for nginx, add location /assets/ { root /path/to/static/files; } for static files, then location / { proxy_pass http://localhost:8080; } for dynamic content. put the static location first or you’ll get routing issues!