title: Nginx to serve static files and also proxy to backend server
body: <p>I'm using nginx to serve static files, and also proxy to a backend java server. I'm using a templating language in my backend java server, that will eventually replace all html files.</p>
  
  <p>I don't know nginx, so I wanted to ask for some help on the most efficient way to do this.</p>
  
  <p>Files:</p>
  
  <pre><code>/assets             // Lots more files in this folder
  /index.html
  /android-chrome-192x192.png
  /android-chrome-512x512.png
  /apple-touch-icon.png
  /browserconfig.xml
  /favicon.ico
  /favicon-16x16.ico
  /favicon-32x32.ico
  /mstile-15x150.png
  /safari-pinned-tab.svg
  /site.webmanifest
  </code></pre>
  
  <p>Here is my conf file so far. I'm serving the static files, but not proxying:</p>
  
  <pre><code>server {
      listen 80 default_server;
      listen [::]:80 default_server;
      root /root/web;
      index index.html;
      server_name _;
  
      location /assets/ {
          try_files $uri =404;
          sendfile on;
          sendfile_max_chunk 512k;
      }
  
      location / {
          try_files $uri =404;
          sendfile on;
          sendfile_max_chunk 512k;
      }
  
      location ~* \.(jpg|jpeg|png|gif|ico|webp|mp4)$ {
          expires 30d;
      }
  
      location ~* \.(css|js)$ {
          expires 10d;
      }
  
      gzip on;
      gzip_vary on;
      gzip_comp_level 4;
      gzip_min_length 256;
      gzip_proxied any;
      gzip_types application/javascript application/json application/x-font-ttf font/opentype image/* text/plain text/css text/xml text/javascript application/x-javascript application/xml;
      gzip_disable "MSIE [1-6]\.";
      gunzip on;
  
      # error_log /root/nginx-log.txt debug;
  }
  </code></pre>
  
  <p>My backend server will serve urls with patterns like this:</p>
  
  <pre><code>/basic-url-here     // This style will serve html files built with a templating language from the server, so they need to be at the root path
  /api/*
  </code></pre>
  
  <p><strong>What is the right / efficient way to serve all these files with nginx while also proxying to a backend server?</strong></p>