How to setup nginx to server static content and reverse proxy a nodejs web server.

Posted November 6, 2017 16.6k views
NginxNode.jsUbuntu 16.04

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/ while still proxying all other requests.

The reverse proxy part works, but the static content is not served when I access the site as or or All of the requests are passed to the nodejs process instead.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer


    location / {
        # First attempt to serve request as file
        try_files $uri $uri/ ;
    location ~ {


    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to proxy
        try_files $uri $uri/ @proxy;
    location @proxy {