Home >Backend Development >PHP Tutorial >The application of Nginx load balancing in Sina Podcast N years ago

The application of Nginx load balancing in Sina Podcast N years ago

WBOY
WBOYOriginal
2016-07-30 13:31:581103browse

The Sina Podcast in 2008 consists of a static server cluster and a dynamic server cluster. The static server cluster uses Squid as the front-end cache. The dynamic server is also called the interface server. It is mainly used to display the number of plays, record play logs, etc.
The interface server uses F5 BIG-IP hardware layer four/seven load balancing switches to perform layer four load balancing on four Nginx reverse proxy servers. The four nginx servers determine the URL, group it, and balance three groups of back-end web servers. Perform seven-layer load balancing.
The three sets of web servers on the F5 BIG-IP backend have different configurations. The first set is memory-intensive and its technology is mainly PHP+Mencache service; the second set is CPU-intensive service and mainly consumes CP resources; the third set is disk-intensive. type, which requires large space for operations such as logging.
The following code is the interface server Nginx load balancing configuration;

<code><span>/***代码是N年前新浪接口服务器的nginx负载均衡配置,提供按URL分组服务,负载均衡服务***/</span>usr www www;
worker_processes <span>10</span>;
error_log /data1/logs/nginx_error.log crit;
pid   /tmp/nginx.pid
worker_rlimt_nofile <span>51200</span>;

events
{
    <span>use</span><span>epull</span>;

    worker_connections <span>51200</span>;
}

http
{
    <span>include</span>  conf/mine.types;
    default_type application/octet-stream;

    charset gb2312;

    server_name_hash_bucket_size <span>128</span>;

    keeplaive_timeout <span>15</span>;

    sendfile on;
    tcp_mopush on;
    tcp_nodelay on;
    <span>#第一组接口机:Memcache相关(点击数)</span>
    upstream count.<span>interface</span>.video.sian.com.cn{
        server xx.xx.xx<span>.55</span>:<span>80</span>;
        server xx.xx.xx<span>.58</span>:<span>80</span>;
        server xx.xx.xx<span>.47</span>:<span>80</span>;
    }
    <span>#第二组接口机:提供数据类程序</span>
    upstream data.<span>interface</span>.video.sian.com.cn{
        server xx.xx.xx<span>.59</span>:<span>80</span>;
        server xx.xx.xx<span>.64</span>:<span>80</span>;
        server xx.xx.xx<span>.48</span>:<span>80</span>;
    }
    <span>#第三组接口机:打日志类程序,功能相关,嵌套页面</span>
    upstream log.<span>interface</span>.video.sian.com.cn{
        server xx.xx.xx<span>.72</span>:<span>80</span>;
        server xx.xx.xx<span>.49</span>:<span>80</span>;
    }
}
server
{
    listen <span>80</span>;
    server_name <span><span>interface</span>.<span>video</span>.<span>sian</span>.<span>com</span>.<span>cn</span>;

    <span>location</span> / {</span>
    proxy_redirect off;

    <span>#后端的web服务器可以直接通过X-Forward-For 获取用户真实ip</span>
    proxy_set_header X-Forward-<span>For</span><span>$remote_adr</span>;

    <span>#按URL进行分组,第一组:Memcache相关(点击数)</span><span>if</span> (<span>$request_uri</span> ~ <span>"^\/app\/count\/"</span>)
    {
        proxy_pass http:<span>//count.interface.video.sian.com.cn;</span>
    }
    <span>if</span> (<span>$request_uri</span> ~ <span>"^\/app\/online\/"</span>)
    {
        proxy_pass http:<span>//count.interface.video.sian.com.cn;</span>
    }
    <span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/user\/getLoginGap.php"</span>)
    {
        proxy_pass http:<span>//count.interface.video.sian.com.cn;</span>
    }
    <span>#按URL进行分组,第二组:外部提供数据类程序</span><span>if</span> (<span>$request_uri</span> ~ <span>"^\/crossdomain.xml"</span>)
    {
        proxy_pass http:<span>//data.interface.video.sian.com.cn;</span>
    }
    <span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/client\/topVideoClient.php"</span>)
    {
        proxy_pass http:<span>//data.interface.video.sian.com.cn;</span>
    }
    <span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/common\/"</span>)
    {
        proxy_pass http:<span>//data.interface.video.sian.com.cn;</span>
    }
    <span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/randplay\/randplay.php"</span>)
    {
        proxy_pass http:<span>//data.interface.video.sian.com.cn;</span>
    }
    <span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/topic\/suggTop.php"</span>)
    {
        proxy_pass http:<span>//data.interface.video.sian.com.cn;</span>
    }
    <span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/uploadClient\/"</span>)
    {
        proxy_pass http:<span>//data.interface.video.sian.com.cn;</span>
    }
    <span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/xml\/"</span>)
    {
        proxy_pass http:<span>//data.interface.video.sian.com.cn;</span>
    }
    <span>if</span> (<span>$request_uri</span> ~ <span>"^\/outinterface\/"</span>)
    {
        proxy_pass http:<span>//data.interface.video.sian.com.cn;</span>
    }
    <span>#按URL进行分组,第三组:打日志类程序</span><span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/flash\/"</span>)
    {
        proxy_pass http:<span>//log.interface.video.sian.com.cn;</span>
    }
    <span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/playrank\/playrank2008_10.php"</span>)
    {
        proxy_pass http:<span>//log.interface.video.sian.com.cn;</span>
    }
    <span>#按URL进行分组,其他组:功能相关,嵌套页面等未匹配到的URL</span>
    proxy_pass  http:<span>//log.interface.video.sina.com.cn;</span>
}
<span>#定义日至格式</span>
log_format count <span>'$remote_addr - $remote_user [$time_local] $request'</span><span>'"$status" $body_bytes_sent "$http_referer"'</span><span>'"$http_user_agent"   "$http_x_forwarded_for"'</span>;
<span>#打日志</span>
access_log /data1/logs/<span><span>interface</span>.<span>log</span><span>count</span>;

#允许客户端请求的最大单文件字节数
<span>client_max_body_size</span> 10<span>m</span>;

#缓冲区代理缓冲用户端的最大字节数 可以理解为现存到本地再传给用户
<span>client_body_size</span> 128<span>k</span>;

#跟后端服务器连接的超时时间<span>_</span>发起握手等候响应超时时间
<span>proxy_connect_time</span> 600;

#连接成功后<span>_</span>等待后端服务器响应时间<span>_</span>其实已经进入后端的派对等候处理
<span>proxy_read_timeout</span>  600;

#后端回传时间<span>_</span>规定时间内传完所有数据
<span>proxy_send_timeout</span>  600;

#代理请求缓存区,保存用户的头信息以供<span>Nginx</span>进行规则处理
<span>proxy_buffer_size</span>  8<span>k</span>;
<span>proxy_buffers</span>   4  32<span>k</span>;
<span>proxy_busy_buffers_size</span>  64<span>k</span>;
<span>proxy_temp_file_write_size</span> 64<span>k</span>;
}
}</span></code>

Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces the application of Nginx load balancing in Sina Podcast N years ago, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn