Home  >  Q&A  >  body text

node - nginx strategy when reverse server hangs

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?

黄舟黄舟2713 days ago410

reply all(2)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 17:17:11

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

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 17:17:11

    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.

    reply
    0
  • Cancelreply