Phoenix 使用七牛作为静态资源存储

在七牛新建一个空间,然后配置「镜像存储」,其中「镜像源」填入网站的地址

记得配置 robots.txt,防止搜索引擎误索引

七牛镜像存储配置图解

修改 /config/prod.exs 文件,在 Endpoint 配置里增加 static_url

 config :daka, Daka.Endpoint,
    http: [ip: {127, 0, 0, 1}, port: 4800],
    url: [scheme: "https", host: "example.com", port: 443],
+   static_url: [scheme: "https", host: "xxx.qnssl.com", port: 443],
    cache_static_manifest: "priv/static/manifest.json"
  
  # Do not print debug messages in production

修改所有的 static_pathstatic_url

     <meta name="onMenuShareTimeline" content="<%= wechat_meta(@conn, :on_menu_share_timeline) %>">
  
      <title>Hello Daka!</title>
 -    <link rel="stylesheet" href="<%= static_path(@conn, "/css/app.css") %>">
 +    <link rel="stylesheet" href="<%= static_url(@conn, "/css/app.css") %>">
    </head>
  
    <body>
 @@ -30,6 +30,6 @@
  
      </div> <!-- /container -->
      <script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
 -    <script src="<%= static_path(@conn, "/js/app.js") %>"></script>
 +    <script src="<%= static_url(@conn, "/js/app.js") %>"></script>
    </body>
  </html>

搞定!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,123评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,993评论 6 342
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,805评论 18 399
  • 那个说我会发光的姑娘你现在 是瞎了吗
    鲁看山阅读 245评论 0 0
  • 一、spring 的作用: 在SSH框假中spring充当了管理容器的角色。我们都知道Hibernate用来做持久...
    xjw_2048阅读 540评论 0 1