好记性不如烂笔头--linux学习笔记8关于nginx的动静分离

动静分离逻辑梳理

就是给nginx配置访问规则,不同后缀的文件访问不同的目录

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

upstream static_pools {
    server 192.168.1.106:8080;
}

upstream dynamic_pools {
    server 192.168.1.103:8080;
}
    server {
        listen       80;
        location / {
            root   html;
            index  index.html index.htm;
            proxy_pass http://dynamic_pools;
        }

        location ~ .*.(gif|jpg|jpeg|png|bmp|swf|css|js)$ { //如果请求包含这些后缀,请求被转发到静态池,否则转发到动态池
            proxy_pass http://static_pools;
        }



    }
}
~
原文地址:https://www.cnblogs.com/baker95935/p/8125017.html