zoukankan      html  css  js  c++  java
  • 5.动静分离

    动态资源代理

    location / {
      proxy_pass 路径;
    }
    

    静态资源代理

    location / {
      root 静态资源路径;
      index 默认访问路径下的什么资源;
      autoindex on; # 带表展示静态资源下的全部内容,以列表的形式展示。
      expires 1d;   # 为客户端设置静态资源缓存时间
    }
    
    
    # 先修改docker,添加数据卷,映射到nginx服务器的一个目录
    [root@localhost docker_nginx]# vi docker-compose.yml
    
    volumes:
          - /opt/docker_nginx/conf.d:/etc/nginx/conf.d
          - /opt/docker_nginx/img:/data/img    # 映射存放图片的目录
          - /opt/decker_nginx/html:/data/html  # 存放静态页面的目录
          
    [root@localhost docker_nginx]# docker-compose down   # 先删除容器
    [root@localhost docker_nginx]# docker-compose up -d  # 再启动容器
    
    [root@localhost html]# vi index.html # 在静态资源目录下添加个页面
    <h1>hello static resource</h1>
    
    [root@localhost img]# ls  # 在img存放一张图片
    1.jpg
    
    
    server{
      listen 80;
      server_name localhost;
    
      location /html {
        root /data;
        index index.html;
      }
    
      location /img {
        root /data;
        autoindex on;
      }
    }
    
    docker-compose restart
    
  • 相关阅读:
    解决Redis之MISCONF Redis is configured to save RDB snapshots
    lnmp一键安装redis以及php组件
    多版本PHP使用composer
    composer设置成阿里云镜像
    Yaf 简介
    Ubuntu配置php7.2开机启动
    Ubuntu查看开机日志
    ssh生成公钥
    Ubuntu系统如何分区
    初始化一个yaf项目
  • 原文地址:https://www.cnblogs.com/eba001/p/14312327.html
Copyright © 2011-2022 走看看