zoukankan      html  css  js  c++  java
  • lnmp1.6 配置负载均衡

    proxy_pass 模式

    upstream httpserver {
            ip_hash;
            server 172.20.39.79 weight=1;
            server 172.20.39.80 weight=1;
            server 172.20.39.81 weight=1;
    }

    server
        {
            listen 80;
            server_name xxx.abc.com *.xxx.abc.com;
            index index.html index.htm index.php default.html default.htm default.php;
            root  /data/www/xxx/Public;

            location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
            {
                expires      30d;
            }

            location / {
                    proxy_set_header Host $host:$server_port;

                    proxy_set_header X-Real-IP $remote_addr;

                    proxy_set_header REMOTE-HOST $remote_addr;

                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

                    proxy_pass http://httpserver;
            }

            #access_log  /data/wwwlogs/xxx.abc.com.log;
        }


    fastcgi_pass 模式

    注意:该模式必须保证在nginx服务器上有php服务器上对应的被请求php文件(只要能找到对应文件名即可,不需要php文件内容相同,空文件即可),主要是因为nginx会检查文件是否存在,单入口模式的系统,只要有index.php就可以了

    nginx 配置,服务器IP 172.20.39.78

    upstream phpserver {
            ip_hash;
            server 172.20.39.79:9000 weight=1;
            server 172.20.39.80:9000 weight=1;
            server 172.20.39.81:9000 weight=1;
    }

    server
        {
            listen 80;
            server_name xxx.abc.com *.xxx.abc.com;
            index index.html index.htm index.php default.html default.htm default.php;
            root  /data/www/xxx/Public;

            if (!-e $request_filename) {
                rewrite ^/(.*)$ /index.php/$1 last;
                break;
            }

            location ~ /uploads/.*.php$ { deny all; }

            location ~ [^/].php(/|$)
            {
                fastcgi_pass  phpserver;
                fastcgi_index index.php;
                include fastcgi.conf;
                include fastcgi_params;
                fastcgi_param PHP_ADMIN_VALUE "open_basedir=/data/www/xxx/:/tmp/:/proc/";
                include pathinfo.conf;
            }

            location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
            {
                expires      30d;
            }

            location ~ .*.(js|css)?$
            {
                expires      12h;
            }

            location ~ /.well-known {
                allow all;
            }

            location ~ /.
            {
                deny all;
            }

            access_log  /data/wwwlogs/xxx.abc.com.log;
    }


    php-fpm.conf 配置 服务器IP 172.20.39.80,其他两台服务器类似

    [global]
    pid = /usr/local/php/var/run/php-fpm.pid
    error_log = /usr/local/php/var/log/php-fpm.log
    log_level = notice

    [www]
    listen = 9000
    listen.backlog = -1
    listen.allowed_clients = 172.20.39.80,127.0.0.1,172.20.39.78
    listen.owner = www
    listen.group = www
    listen.mode = 0666
    user = www
    group = www
    pm = dynamic
    pm.max_children = 600
    pm.start_servers = 80
    pm.min_spare_servers = 20
    pm.max_spare_servers = 600
    pm.max_requests = 4096
    pm.process_idle_timeout = 10s
    request_terminate_timeout = 100
    request_slowlog_timeout = 0
    slowlog = /var/log/slow.log

  • 相关阅读:
    Kubernetes 部署 Kubernetes-Dashboard v2.0.0
    Kubernetes 部署 Metrics Server 获取集群指标数据
    内网终端安全建设(转)
    内网安全运营的逻辑体系架构(转)
    thinkphp5配置文件
    MySQL索引失效的几种情况
    workman使用
    长连接技术(Long Polling)
    php好文章的记录
    php类与对象得使用场景
  • 原文地址:https://www.cnblogs.com/lbnnbs/p/13629893.html
Copyright © 2011-2022 走看看