Nginx – Configure nginx to serve static files

file-servergoogle-compute-enginenginxstatic-content

I'm trying to serve static files(HTMLs, JS and CSS) from a Google compute engine instance running Debian 8.
I used git to clone the web app to the folder /var/www/prod/app with command

sudo git clone <my repo>

I made a conf file in sites-enabled folder app.conf. Here's the content

server {
    listen 80;
    root /var/www/prod/app;
    location / {
    }
}

Isn't this config enough to make my machine serve the files when I type my machine's ip address/path ?

I see the welcome to nginx page when I type my instance's ip address in browser. But none of the files in prod/app are served. I get 404 for all the paths I try. Could someone help me configure this.

Best Answer

You need to add try_files inside location and make it the default server:

server {
    listen 80 default_server;

    root /var/www/prod/app;

    location / {
        try_files $uri $uri/ /index.html;
    }
}

Then you need to restart the nginx service.