动静分离
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; 的效果