title: Node app on Nginx is downloading the index.html instead of updating it
body: <p>First, <strong>this has nothing to do with php.</strong> </p>
  
  <p>I followed <a href="https://code.lengstorf.com/deploy-nodejs-ssl-digitalocean/" rel="nofollow noreferrer">this</a> tutorial to deploy a small node app to digitalocean. There is a button in my app that grabs some text and then updates a div on the page with it. The problem occurs when running on a live nginx server; the button causes the browser to download the index.html of the app instead of just updating the page. When testing on local host I cannot get this to happen, meaning it has to do with the nginx configuration. When I looked up this problem, all of the solutions are centered around serving php files. My <code>/etc/nginx/sites-enabled/default</code>just looks like this</p>
  
  <pre><code>upstream node-upstream {
      server MY_IP_ADDRESS:5000;
  }
  
  server {
      listen 80 default server;
      listen [::]:80 default_server ipv6only=on;
      return 301 https://$host$request_uri;
  
      server_name &lt;my_site&gt;.com www.&lt;my_site&gt;.com;
  }
  
  server {
      listen 443 ssl http2;
      listen [::]:443 ssl http2 ipv6only=on;
  
      root /path/to/app;
      index index.html;
  
      server_name &lt;my_site&gt;.com www.&lt;my_site&gt;.com;
  
      ssl_certificate /etc/letsencrypt/live/&lt;my_site&gt;.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/&lt;my_site&gt;.com/privkey.pem;
  
      include snippets/ssl-params.conf;
  
      location / {
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-NginX-Proxy true;
          proxy_pass http://localhost:5000;
          proxy_set_header Host $http_host;
          proxy_cache_bypass $http_upgrade;
          proxy_redirect off;
      }
  }
  </code></pre>
  
  <p><strong>Edit:</strong> When I use <code>curl -v https://&lt;my_site&gt;.com/</code> it also outputs the entire index.html in the terminal, but right after showing this</p>
  
  <pre><code>* Rebuilt URL to: https://&lt;my_site&gt;.com/
  *   Trying &lt;IPV6_ADDRESS&gt;...
  * TCP_NODELAY set
  * Connected to &lt;my_site&gt;.com (&lt;IPV6_ADDRESS&gt;) port 443 (#0)
  * ALPN, offering http/1.1
  * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
  * successfully set certificate verify locations:
  *   CAfile: /anaconda3/ssl/cacert.pem
    CApath: none
  * TLSv1.2 (OUT), TLS header, Certificate Status (22):
  * TLSv1.2 (OUT), TLS handshake, Client hello (1):
  * TLSv1.2 (IN), TLS handshake, Server hello (2):
  * TLSv1.2 (IN), TLS handshake, Certificate (11):
  * TLSv1.2 (IN), TLS handshake, Server key exchange (12):
  * TLSv1.2 (IN), TLS handshake, Server finished (14):
  * TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
  * TLSv1.2 (OUT), TLS change cipher, Client hello (1):
  * TLSv1.2 (OUT), TLS handshake, Finished (20):
  * TLSv1.2 (IN), TLS change cipher, Client hello (1):
  * TLSv1.2 (IN), TLS handshake, Finished (20):
  * SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
  * ALPN, server accepted to use http/1.1
  * Server certificate:
  *  subject: CN=&lt;my_site&gt;.com
  *  start date: Jun 27 05:34:01 2018 GMT
  *  expire date: Sep 25 05:34:01 2018 GMT
  *  subjectAltName: host "&lt;my_site&gt;.com" matched cert's "&lt;my_site&gt;.com"
  *  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
  *  SSL certificate verify ok.
  &gt; GET / HTTP/1.1
  &gt; Host: &lt;my_site&gt;.com
  &gt; User-Agent: curl/7.58.0
  &gt; Accept: */*
  &gt;
  &lt; HTTP/1.1 200 OK
  &lt; Server: nginx/1.14.0
  &lt; Date: Wed, 27 Jun 2018 21:31:14 GMT
  &lt; Content-Type: text/html; charset=UTF-8
  &lt; Content-Length: 3030
  &lt; Connection: keep-alive
  &lt; X-Powered-By: Express
  &lt; Accept-Ranges: bytes
  &lt; Cache-Control: public, max-age=0
  &lt; Last-Modified: Wed, 27 Jun 2018 12:56:18 GMT
  &lt; ETag: W/"bd6-1644150e6fc"
  &lt; Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
  &lt; X-Frame-Options: DENY
  &lt; X-Content-Type-Options: nosniff
  &lt; X-XSS-Protection: 1; mode=block
  &lt;
  </code></pre>
  
  <p>The code in the node app responsible for updating is this:</p>
  
  <pre><code>const express = require('express');
  const router = express.Router();
  
  // serve the index.html
  router.get('/', (req, res) =&gt; {
    res.setHeader('Content-Type', 'text/html');
    let file_contents = fs.readFileSync("./public/index.html", {encoding: "utf8"});
    res.write(file_contents);
    res.end();
  });
  
  // grab the text and reload the index.html
  router.post('/', (req, res) =&gt; {
    req.on("data", function(input_value) {
      let query = input_value.toString();
      let num_paragraphs = query.split("=").pop();
      let hi_text = my_db.getAllParagraphs(num_paragraphs);
      let file_contents = fs.readFileSync("./public/index.html", {encoding: "utf8"});
      file_contents = file_contents.replace("&lt;span class='hit'&gt;&lt;/span&gt;", hi_text);
      res.write(file_contents);
      res.end();
    });
  });
  
  module.exports = router;
  </code></pre>