Home Backend Development PHP Tutorial The application of Nginx load balancing in Jinshan Xiaoyao Network N years ago

The application of Nginx load balancing in Jinshan Xiaoyao Network N years ago

Jul 30, 2016 pm 01:31 PM


In Jinshan Xiaoyao.com, the front-end load balancing server uses Nginx. Two Nginx servers form a group to undertake various types of load balancing services. Both load balancing servers are active and each is bound to one. Public network virtual IP serves as a load balancing server. When one of them fails, the other takes over the virtual IP of the failed server. The configuration nginx.conf code is as follows

Code:

user www www;
work_processes 8;
error_log /data1/logs/nginx_error.log crit;
pid /usr/local/webserver/nginx/nginx.pid;#specifies the value for maximum file descriptors that can be opened 
by this process worker_rlimit_nofile 51200events
{
    use epoll;
    worker_connections 51200;
}

http
{
     include    mine.types;
     default_type  application/octet-strem;     #charset utf-8     server_names_hash_bucket_size 128k;
     client_header_buffer_size  32k;
     large_client_header_buffers 432k;

     sendfile on;     #tcp_nopush on;     keepalive_timeout 30;
     tcp_nodelay on;

     fastcgi_connect_timeout  300;
     fastcgi_send_timeout 300;
     fastcgi_read_timeout 300;
     fastcgi_buffer_size 64k;
     fastcgi_buffers 464k;
     fastcgi_busy_buffers_size  128k;
     fastcgi_temp_file_write_size  128k;

     gzip on;
     gzip_min_length 1k;
     gzip_buffers  416k;
     gzip_http_version 1.1 gzip_comp_level 2;
     gzip_types  text/plain  application/x-javascript  text/css  application/xml;
     gzip_vary on;

    limit_zone anti_attack $binary_remote_addr10m;
    #允许客户端请求的最大单文件字节数client_max_body_size 300m;
    #缓冲区代理缓冲用户端的最大字节数 可以理解为现存到本地再传给用户client_body_size 128k;
    #跟后端服务器连接的超时时间_发起握手等候响应超时时间proxy_connect_time 600;
    #连接成功后_等待后端服务器响应时间_其实已经进入后端的派对等候处理proxy_read_timeout  600;
    #后端回传时间_规定时间内传完所有数据proxy_send_timeout  600;
    #代理请求缓存区,保存用户的头信息以供Nginx进行规则处理proxy_buffer_size  16k;
    proxy_buffers   432k;
    proxy_busy_buffers_size  64k;
    proxy_temp_file_write_size 64k;#缓存proxy_temp_path /data2/proxy_temp_path;
    proxy_cache_path  /data2/proxy_cache_path levels=1:2 keys_z>200m inactive=1d max_size=5;

    upstream myserver_pool{
        server xx.xx.xx.1:80 weight=1 max_fails=2 fail_timeout=30s;
        server xx.xx.xx.2:80 weight=1 max_fails=2 fail_timeout=30s;
        server xx.xx.xx.3:80 weight=1 max_fails=2 fail_timeout=30s;
    }

    upstream php_server_pool{
        server xx.xx.xx.4:80 weight=1 max_fails=2 fail_timeout=30s;
        server xx.xx.xx.5:80 weight=1 max_fails=2 fail_timeout=30s;
        server xx.xx.xx.6:80 weight=1 max_fails=2 fail_timeout=30s;
        server xx.xx.xx.7:80 weight=1 max_fails=2 fail_timeout=30s;
        server xx.xx.xx.8:80 weight=1 max_fails=2 fail_timeout=30s;
    }

    upstream bbs_server_pool{
        ip=hash;
        server xx.xx.xx.9:80 max_fails=2 fail_timeout=30s;
        server xx.xx.xx.10:80 max_fails=2 fail_timeout=30s;
        server xx.xx.xx.11:80 max_fails=2 fail_timeout=30s;
        server xx.xx.xx.12:80 max_fails=2 fail_timeout=30s;
    }

    upstream cms_server_pool{
        server xx.xx.xx.13:80 weight=1 max_fails=2 fail_timeout=30s;
        server xx.xx.xx.14:80 weight=1 max_fails=2 fail_timeout=30s;
    }

    upstream pic_server_pool{
        server xx.xx.xx.15:80 weight=1 max_fails=2 fail_timeout=30s;
        server xx.xx.xx.16:80 weight=1 max_fails=2 fail_timeout=30s;
    }

    upstream xoyohimsg_server_pool{
        server xx.xx.xx.17:3245;
        server xx.xx.xx.18:3245 down;
    }#xoyo.com域名调转到www.xoyo.com    server
    {
        listen 80;
        server_name xiyo.com;

        rewrite ^/(.*) http:xoyo.com/ permanent;

        acces_log /data1/logs/xoyo.com_access.log;
    }#用户中心HTTP/SSL加密浏览server
    {
        listen 443;
        server_name my.xoyo.com

        ssl on;
        ssl_cretificate  my.xoyo.com.crt;
        ssl_cretificate_key my.xoyo.com.key;

    location /
    {
        proxy_pass http://php_server_pool;
        proxy_set_header Host my.xoyo.com;
        proxy_set_header X-Forward-For $remote_addr;
    }
    access_log /data1/logs/my.xoyo.com_access.log;

    }#图片服务器,不同的路径访问后端不同的服务器server
    {
        listen 80;
        server_name pic.xoyo.com;

        location /cms/
        {
        proxy_pass http://cms_server_pool;
        proxy_set_header Host pic.xoyo.com;
        proxy_set_header X-Forward-For $remote_addr;
        }
        access_log /data1/logs/pic.xoyo.com_access.log;
    }#音频电台文件下载,进行简单防盗链#limit_zone media %binary_remote_addr 10m;server
    {
        listen 80;
        server_name media.xoyo.com;

        location /
        {
        proxy_pass http://cms_server_pool;
        proxy_set_header Host $host;
        proxy_set_header X-Forward-For $remote_addr;

        valid_reference nine blocked www.xoyo.com *.xoyo.com  www.kingsoft.com  
        *.kingsoft.com  www.kingsoft.cn  
        *.kingsoft.cn;if ($invalid_referers){
            rewrite ^/ http://www.xoyo.com;
        }
        }
        access_log /data1/logs/media.xoyo.com_access.log;
    }#“逍遥有聊”WebIM产品的负载均衡,反向代理两种HTTP服务器server
    {
        listen  80;
        server_name hi.xoyo.com;#反向代理一款定制开发的高性能消息队列HTTP服务器location /recmessage.xoyo
    {
        proxy_pass http://xoyohimsg_server_pool;
        proxy_set_header Host $host;
    }

    location /
    {
        proxy_pass http://php_server_pool;
        proxy_set_header Host $host;
        proxy_set_header X-Forward-For $remote_addr;

    }

    access_log /data1/logs/hi.xoyo.com_access.log;
    #论坛负载均衡并对图片、Flash、JavaScript、CSS、静态HTML进行Web缓存server {
    listen   80;
    server_name bbs.xoyo.com *.bbs.xoyo.com bbs.xoyo.kingsoft.com;

    location /
    {
        proxy_pass http://bbs_server_pool;
        proxy_set_header Host $host;
        proxy_set_header X-Forward-For $remote_addr;

    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|html|shtml)$
    {
        proxy_cache  cache_one;
        proxy_cache_valid  20010m;
        proxy_cache_valid  3041m;
        proxy_cache_valid  301302 ih;
        proxy_cache_valid  any 1m;
        proxy_cache_key $host$uri$is_args$args;
        proxy_set_header  Host  $host;
        proxy_set_header X-Forward-For $remote_addr;
        proxy_pass http://bbs_server_pool;

    }
    log_format bbs '
    $remote_addr $host  
    $remote_user [$time_local] "$request"''"$status" 
    $body_bytes_sent "$http_referer"''"$http_user_agent"   "$http_x_forwarded_for"';
access_log /data1/logs/bbs.xoyo.com_access.log bbs;

}#论坛附件反向代理,限制下载速度为256k/秒server{
        listen 80;
        server_name  att03.bbs.xoyo.com  att02.bbs.xoyo.com  att01.bbs.xoyo.com;

    location /{#限制下载速度为256k/slimit_rate 256k;
        proxy_pass http://xx.xx.xx.19;
        proxy_set_header Host $host;
        proxy_set_header X-Forward-For $remote_addr;
    }
    access_log off;
}#逍遥江湖SNS社区,管理后台定位到一台服务器上,并对图片,flash,javascript,CSS进行web缓存    server
    {
        listen  80;
        server_name  hu.xoyo.com  *.hu.xoyo.com;

        location /
        {

        proxy_pass http://php_server_pool;
        proxy_set_header Host $host;
        proxy_set_header X-Forward-For $remote_addr;
        }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
    {
        proxy_cache  cache_one;
        proxy_cache_valid  20010m;
        proxy_cache_valid  3041m;
        proxy_cache_valid  301302 ih;
        proxy_cache_valid  any 1m;
        proxy_cache_key $host$uri$is_args$args;
        proxy_set_header  Host  $host;
        proxy_set_header X-Forward-For $remote_addr;
        proxy_pass http://php_server_pool;
    }

    location ~ ^/admincp.php
    {
        proxy_set_header  Host  $host;
        proxy_set_header X-Forward-For $remote_addr;
        proxy_pass http://xx.xx.xx.4;

    }
    access_log /data1/logs/hu.xoyo.com_accsee.log;
    }
}
Copy after login


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 Jinshan Xiaoyao Network N years ago, including relevant content. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to configure nginx in Windows How to configure nginx in Windows Apr 14, 2025 pm 12:57 PM

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

How to configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

How to start nginx server How to start nginx server Apr 14, 2025 pm 12:27 PM

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

See all articles