HP_69 2017-03-23 02:49 采纳率: 0%
浏览 1005

nginx 负载均衡这样设置配置文件对吗?如何测试负载均衡?

user nobody nobody;
worker_processes 3;

pid logs/nginx.pid;

events {
worker_connections 1024;
use epoll;

}

http {
include mime.types;
default_type application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  logs/access.log  main;

sendfile        on;

keepalive_timeout  65;

    gzip on;
    gzip_min_length 1024;
    gzip_buffers 4 16k;
    gzip_comp_level 2;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    #gunzip_static on;


    upstream backend
    {
            server 192.168.1.30:8081;
            server 192.168.1.31:8081;
            server 192.168.1.32:8081;
    }

server {
listen 8081;
server_name 192.168.1.30;
error_page 404 /404.html;

    location / {
            root myweb;
            index index.30.htm;
    }
    location /server0/location1 {
            root myweb;
            index index.svr0-loc1.htm;
    }      
    location /svr0/loc2 {
            alias myweb/server0/location2/;
            index index.svr0-loc2.htm;
    }


}

server {
    listen  8081;
    server_name 192.168.1.31;
    error_page 404 /404.html;

    location / {
            root myweb;
            index index.31.htm;
    }
    location /server1/location1 {
            root myweb;
            index index.svr1-loc1.htm;
    }      
    location /svr1/loc2 {
            alias myweb/server1/location2/;
            index index.svr1-loc2.htm;
    }


}

server {
listen 8081;
server_name 192.168.1.32;
error_page 404 /404.html;

    location / {
            root myweb;
            index index.32.htm;
    }
    location /server2/location1 {
            root myweb;
            index index.svr2-loc1.htm;
    }      
    location /svr2/loc2 {
            alias myweb/server2/location2/;
            index index.svr2-loc2.htm;
    }


}

    server {
            listen 8081;
            server_name myserver;
            #index index.html index.htm;
            location / {
                    proxy_pass http://backend;
                    proxy_set_header Host $host;

            }

    }

}

  • 写回答

1条回答 默认 最新

  • qq_14806125 2017-03-23 09:36
    关注

    测试负载均衡:修改访问页面的内容。让不同服务器的界面显示内容不一样。之后访问,就能知道配置是否成功

    评论

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集