Note that there are some explanatory texts on larger screens.

plurals
  1. POvarnish, nginx, & node.js: static nginx html pages with node.js fallback
    primarykey
    data
    text
    <p>am running varnish on EC2 in front of nginx which routes to node.js.</p> <p>What I would like is to serve specific static HTML pages from certain routes (like, <code>/</code> for <code>index.html</code>) via nginx, but have all other routes be handled by node.js.</p> <p>As an example, <code>/</code> would be sent by nginx in the form of a static HTML page, while anything not matching, say <code>/dynamic_stuff</code> or <code>/dynamic_stuff2</code>, would be processed by node.js.</p> <p>In other threads online, other people were putting node.js in a separate dir entirely, like <code>/node/dynamic_stuff</code> but I didn't want to have a separate dir for my routing.</p> <p>Right now I have <code>/</code> served up by node.js like everything else but if I'm just testing my node.js server and I take it down, I'd like <code>/</code> to fallback to an nginx version of <code>index.html</code>. In this case, if my node.js server is taken down, then I get a 502 Bad Gateway.</p> <p>I'm not too worried about performance from serving up files via nginx vs. node.js, I just figure that I want to have nginx handling basic pages if node.js goes down for whatever reason.</p> <p>Relevant script:</p> <pre><code>location = / { index index.html root /path/to/public try_files $uri $uri/ index.html; } location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass node_js; } </code></pre> <p>If I use this above code, all requests still get sent to node.js, including <code>/</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload