Nginx安装与配置集群负载均衡代理proxy

一、下载Nginx

1、登录官网http://nginx.org/下载

2、网盘链接:https://pan.baidu.com/s/1_HC5C_PvsRfYWhFR0V89Uw密码:78a1

二、 配置

说明:配置文件在conf\nginx.conf

1、 部署系统:

    #请求Url:localhost:80/index.html
    #物理地址:D:/Study/Study/NginxTest/index.html
    server {
        listen       80;
        server_name  127.0.0.1 localhost;
        location / {
            root   D:/Study/Study/NginxTest;
            index  index.html index.htm;
        }
   }

2、反向代理:

    server {
        listen       80;
        server_name  127.0.0.1 localhost;
        location / {
            root   D:/Study/Study/NginxTest;
            index  index.html index.htm;
        }
        #反向代理 : 使用正则匹配
        location ~ \.(jpg|png|jpeg|gif)$ {
            proxy_pass  http://site.com;
        }
    }

3、集群负载均衡:

#网站A
server {
        listen       8099;
        server_name  localhost;
        location / {
            root   D:/Study/Study/NginxTestOne;
            index  index.html index.htm;
        }
   }

#网站B
server {
        listen       8098;
        server_name  localhost;
        location / {
            root   D:/Study/Study/NginxTestTwo;
            index  index.html index.htm;
        }
   }

  #集群/负载均衡服务器列表
   upstream outServer{
             serverlocalhost:8099 weight=1 max_fails=2 fail_timeout=3s;
             serverlocalhost:8098 weight=1 max_fails=2 fail_timeout=3s;
   }

   server {
        listen       80;
        server_name  localhost;
        keepalive_timeout  30; #连接超时3秒
        location / {
                  proxy_pass http://outServer;
        }
   }

三、使用

说明:最好以dos命令的方式来操作

1、切换到安装包目录:Win+R  => cmd =>cd 安装包目录

2、nginx常用启动命令

               a. 启动:start nginx

               b. 修改配置后重新加载生效:nginx -s reload  

               c. 重新打开日志文件:nginx -sreopen 

               d. 测试nginx配置文件是否正确:nginx -t -c/path/to/nginx.conf

               e. 快速停止nginx nginx -s stop

               f. 完整有序的停止nginxnginx -s quit 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值