Home  >  Q&A  >  body text

Can Nginx upstream cross computer rooms?

As the title states, can the configuration of Nginx Upstream be set to the external network IP across computer rooms?
It's okay to test it yourself, but I don't know what problems will occur in the actual environment.
When Nginx upsteam is used as a front-end proxy, it uses a long connection, which may cause problems due to poor network or something.
Can anyone with experience or experience in this field please give me an answer?

PHP中文网PHP中文网2712 days ago769

reply all(2)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-16 17:29:09

    My website is across computer rooms, one nginx is used as a reverse proxy, and the real web server is in another computer room

    The nginx configuration for reverse proxy is roughly as follows:

    upstream real.sites {
        server 123.123.123.123;
    
        // 用keepalive保存长连接,降低频繁创建连接的开销
        keepalive 16;
    }
    
    proxy_cache_path /path/to/cache levels=1:2 keys_zone=static_cache:100m;
    
    server {
        server_name     www.example.com;
    
        // 把真正的IP地址放到header的X-Forwarded-For里面
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    
        proxy_next_upstream http_503;
    
        // 把静态资源缓存起来,减少服务器间数据传输
        location ~ \.(css|js|jpg|png|gif|ico)$ {
            proxy_cache static_cache;
            proxy_pass http://real.sites;
        }
    
        location / {
            proxy_pass http://real.sites;
        }
    }
    

    This deployment method is greatly affected by the quality of the network in the computer room. If the network in the computer room is strong, it will be fine. nginx itself has not caused any trouble.

    In fact, varnish should be more suitable for this than nginx. However, I am not familiar with varnish, so I just use nginx.

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-16 17:29:09

    Properly.

    reply
    0
  • Cancelreply