node - nginx strategy when reverse server hangs
黄舟
黄舟 2017-05-16 17:15:11
0
2
442

When doing node isomorphism, now I want to let nginx directly return static resources when the server is called. How should I configure nginx?

For example, visit a.xx.com/test.html,
When the node server hangs up, let nginx directly return the static file of test.html. Is there a way to achieve this?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(2)
曾经蜡笔没有小新

Use proxy_intercept_errors + error_page to solve your problem.
error_page 504 /$uri
504 means that the proxy times out

phpcn_u1582

We originally encountered your problem when we were publishing. When we were publishing, we needed to stop the service
But we hope to have a friendly page to remind users that we are serving and please try again later. We use nginx's load balancing to start two services. 10.0.0.2 runs to prompt users that we are releasing a version and prompts users to use the service.

upstream my_server {                                                         
    server 10.0.0.1:8080 weight=10;
    server 10.0.0.2:8080 backup;   //当其它服务器挂掉的时候才会负载到这台                                             
    keepalive 2000;
}
server {
    listen       80;                                                         
    server_name  www.test.com;                                               

    location / {
        proxy_pass http://my_server;
    }
}

However, we are already using slb for G/B issue, and the service will not be stopped during the release period. I hope it can help you. I am not very proficient in nginx. I hope there is a more clever way to solve this problem. In fact, if you write your own Lua script, you can do some customized functions. You should consider your team and time. I think It's actually best if you can do it.
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template