Nginx

Nginx

主要两个点: 反向代理负载均衡

正向代理

代理服务器代理了客户端,去和目标服务器进行交互 应用场景: 黄牛买票

优点: 突破IP访问限制,;通过缓存加速访问资源;隐藏客户端真实IP;客户端访问授权

反向代理

代理服务器代理了目标服务器,去和客户端交互,应用场景: 客服热线

优点: 隐藏服务器真实IP;负载均衡;通过缓存加速访问资源;提高安全保障

配置

安装
#下载
wget http://nginx.org/download/nginx-1.18.0.tar.gz
#解压
tar zxvf nginx-1.18.0.tar.gz 
#打开目录
cd nginx-1.18.0/
#安装nginx依赖
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl-devel

#配置nginx安装目录
./configure --prefix=/home/luochen/nginx/bin

#编译并安装ls
make && make install

#到只能装目录下启动 
#启动 默认端口80
安装目录/sbin/nginx  
sbin/nginx -s reload  #重启


#设置用户
yum -y install httpd-tools  #安装 htpasswd 工具
htpasswd -c /home/luochen/nginx/bin/.passwd-www 用户名 #生成用户登录的认证文件

常用命令

  -?,-h         : this help #帮助
  -v            : show version and exit #查看版本信息
  -V            : show version and configure options then exit  #查看版本和配置信息
  -t            : test configuration and exit	#测试配置有没有问题
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /home/luochen/nginx//)  #设置路径
  -c filename   : set configuration file (default: conf/nginx.conf)	#按照配置文件启动
  -g directives : set global directives out of configuration file

负载均衡

轮询与权重

/home/luochen/nginx/bin/conf/nginx.conf
#编辑配置文件
vim nginx.conf

 #配置要代理的服务器集群
 # weight: 权重,默认为1
     upstream tomcat{
        server 192.168.163.129:8080 weight=1;
        server 192.168.163.130:8080 weight=1;
        server 192.168.163.131:8080 weight=1;
        }
    #监听服务端口
    server {
        listen       80;
        server_name  localhost;

        #开启用户认证
        auth_basic "User Authentication";
        #配置认证文件
        auth_basic_user_file /home/luochen/nginx/bin/.passwd-www;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        #tomcat: 引用代理的服务器
        location / {
            proxy_pass http://tomcat;
            #root   html;
            #index  index.html index.htm;
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值