nginx-配置实例-负载均衡

1.实现效果:
浏览器地址栏输入地址:http://192.168.10.46/edu/a.html,负载均衡效果,平均8080和8081端口中.
2.准备工作
(1)准备两台tomcat服务器,一台8080,一台8081
(2)在两台tomcat里面webapps目录中,创建名称是edu文件夹,在edu文件夹中创建页面a.html,用于测试.

tomcat8080: webapp/edu/a.html
<h1>8080</h1>
tomcat8081: webapp/edu/a.html
<h1>8081</h1>

defoult.conf
修改内容:
1.添加upstream 并命名为myserver和代理的两个tomcat地址
2.在location中修改代理地址为:myserver
在这里插入图片描述

root@b5e3f7aeee7b:/etc/nginx/conf.d# cat default.conf 
upstream myserver {
 server 192.168.10.46:8080;
 server 192.168.10.46:8081;

}

server {
    listen       8099;
    server_name  192.168.10.46;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;

        proxy_pass   http://myserver;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

运行nginx:

docker run -d --name nginx11 -p 8099:8099  -v /qj/nginx/conf.d/:/etc/nginx/conf.d/ nginx

访问:192.168.10.46:8099/edu/a.html

在这里插入图片描述
在这里插入图片描述

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 游动-白 设计师: 上身试试
应支付0元
点击重新获取
扫码支付

支付成功即可阅读