02-nginx-动静分离

动静分离

1、nginx的并发能力

2、nginx的动态代理

3、nginx的静态代理

 


1、nginx的并发能力

worker_processes * worker_connections / 4 =动态的并发能力

worker_processes * worker_connections / 2 =静态的并发能力

 

 

2、nginx的动态代理
    location / {
         proxy_pass http://tomcat80/muop/;
    }

3、nginx的静态代理

docker-compose.yml 如下:

version: '3.1'
services:
  nginx01:
      restart: always
      image: daocloud.io/library/nginx:latest
      container_name: nginx01
      ports:
        - 80:80
      environment:
        TZ: Asia/Shanghai
      volumes:
        - /root/nginx/conf.d:/etc/nginx/conf.d
        - /root/nginx/img/:/data/img
        - /root/nginx/html/:/data/html

[root@centos701 conf.d]# pwd
/root/nginx/conf.d
[root@centos701 conf.d]# ll 
total 4
-rw-r--r--. 1 root root 749 May 10 12:10 default.conf
[root@centos701 conf.d]# 

default.conf 内容如下:

upstream tomcat80 {
    ip_hash;
    server 192.168.181.138:8080 weight=10;
    server 192.168.181.138:8081 weight=2;

}


server {
    listen       80;   #监听端口是80
    listen  [::]:80;   #
    server_name  localhost;   #接受请求的IP

    location /html {
        # proxy_pass http://tomcat80/muop/;
        # proxy_pass http://192.168.181.138:8081/muop/;
        root   /data;   #root 将接受到的请求根据 /usr/share/nginx/html去查找静态资源
        index  index.html ;    #查找index.html  和 index.htm 响应给客户
    }

    location /img {
        root  /data;
        autoindex on;
    }


    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

 

http://192.168.181.138/img/  可以展示   autoindex on; 的效果


 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值