By bronzetab
I have a droplet setup with nginx using server blocks to have several virtual hosts, letsencrypt and nodejs running: thanks to the great tutorials. I’m using koa.js for the nodejs webserver and I use react to build the static files. I would like to configure nginx to serve the static files from /var/ww/whatever.com while still proxying all other requests.
The reverse proxy part works, but the static content is not served when I access the site as foo.com/ or foo.com/index or foo.com/index.html. All of the requests are passed to the nodejs process instead.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Change
location / {
# First attempt to serve request as file
try_files $uri $uri/ ;
}
location ~ {
To
location / {
# First attempt to serve request as file, then
# as directory, then fall back to proxy
try_files $uri $uri/ @proxy;
}
location @proxy {
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.