Can Nginx upstream cross computer rooms?
PHP中文网
PHP中文网 2017-05-16 17:27:09
0
2
759

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中文网

认证0级讲师

reply all(2)
淡淡烟草味

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.

巴扎黑

Properly.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!