美文网首页
nginx负载均衡傻瓜式配置demo

nginx负载均衡傻瓜式配置demo

作者: 寂寞的棍棍 | 来源:发表于2019-07-12 16:05 被阅读0次

服务器:主服务器ip 172.31.242.250 、从服务器ip 172.31.242.249

主服务器nginx配置文件(172.31.242.250)

upstream travel { 
    #weigth越大压力越大 根据服务器情况自定义
    server 172.31.242.249:81 weight=3;  
    server 172.31.242.250:81 weight=3;   
}

server {
    listen       80;
    listen       443 ssl;                    #htpps证书配置,没有证书直接注释
    server_name  www.sslyzx.com;             #域名配置

    #htpps证书配置,没有证书直接注释
    ssl_protocols TLSv1.2 TLSv1.1 TLSv1;                                                             
    ssl_certificate /usr/local/nginx/conf/sslyzx_ssl/1_star_sslyzx_com_bundle.crt;  
    ssl_certificate_key /usr/local/nginx/conf/sslyzx_ssl/2_star_sslyzx_com.key;      
    ssl_prefer_server_ciphers on;                                                                             

    location / {
        proxy_pass http://travel/;
        proxy_set_header Host  $host;
        proxy_connect_timeout 2s;
    }

}

server {
    listen      81;
    server_name  172.31.242.250;
    root        /data/www/travel/public;
    index        index.php index.html;

    access_log  /etc/nginx/logs/access_log.log;
    error_log    /etc/nginx/logs/error_log.log;

    location / {
            index  index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$query_string;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ \.php$ {
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_index  index.php;
            include        fastcgi_params;
            break;
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}

从服务器nginx配置文件(172.31.242.249)

server {
        listen       81;
        server_name  172.31.242.249;

        root        /data/www/travel/public;
        index        index.php index.html;

        access_log  /etc/nginx/logs/access_log.log;
        error_log    /etc/nginx/logs/error_log.log;

        location / {
                index  index.php index.html index.htm;
                try_files $uri $uri/ /index.php?$query_string;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

      location ~ \.php$ {
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_index  index.php;
                include        fastcgi_params;
                break;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
}

相关文章

网友评论

      本文标题:nginx负载均衡傻瓜式配置demo

      本文链接:https://www.haomeiwen.com/subject/voqykctx.html