zoukankan      html  css  js  c++  java
  • nginx动静分离配置

    动静分离:

    所谓动静分离指的是当访问静态资源时,路由到一台静态资源服务器,当访问是非静态资源时,路由到另外一台服务器

    静态资源配置:

    如配置如下location

    表示url为  /static/*.xxx 的图片或者js等静态资源则会到/html/static目录下去寻找资源

    location /static/~(.*)(.jpg|.png|.gif|.jepg|.css|.js|.css){
      alias html;
    }

    动态资源配置:

    其他访问url则转发到proxy_pass 指向的 http://192.168.25.35:8080;

    location / {
      proxy_pass http://192.168.25.35:8080;

    }

    完整的配置如下:

    server {
      listen 80;
      server_name 192.168.25.35; #  当接收到http请求时,首先host和这里的server_name进行匹配,如果匹配上,则走这个虚拟主机的location路由

      location /static/~(.*)(.jpg|.png|.gif|.jepg|.css|.js|.css){  #  静态资源则路由到这里
        alias html;
      }

      location / {  #  其他的url则转发到 http://192.168.25.35:8080
        proxy_pass http://192.168.25.35:8080;

      }

    }

    以上就是基于url进行动静分离的配置思路,接下来会继续分享怎么配置负载均衡,更多精彩内容,请关注微信公众号

  • 相关阅读:
    aspscheduler+uwsgi定时任务执行多次
    django定时任务
    django记录用户操作模块
    python缩小图片
    pymysql同时执行多条语句时报错
    MySQL8.0 修改密码
    linux中安装python3
    Mysql高性能
    Mysql高性能
    Mysql高性能
  • 原文地址:https://www.cnblogs.com/yaoqingzhuan/p/10890833.html
Copyright © 2011-2022 走看看