0

因此,经过三周的 12 小时轮班后,我几乎完成了使用 Apostrophe 构建知识库系统的工作。现在是在前端加快速度的任务。我的问题是:

  1. 如何添加过期标头:Express 内置了名为 static 的温和软件,我可以在 index.js 文件下正常实现吗?
  2. 缩小 JavaScript 和 CSS:http ://apostrophecms.org/docs/modules/apostrophe-assets/我看到撇号有一些内置但不清楚如何启用它?而且我是否需要将资产放在特定文件夹中才能正常工作?现在我在 lib/modules/apostrophe-pages/public/js 下拥有所有 JS 文件,在 public/css 下拥有 CSS。
  3. 在服务器上启用 GZIP:没有提到,但 express 确实有 gzip 模块,我可以在 lib/modules/apostrophe-express/index.js 下实现它们吗?

任何帮助将不胜感激。

4

1 回答 1

2

我是 P'unk Avenue 的 Apostrophe 的首席开发人员。

听起来你找到了我们的部署 HOWTO 以及最近添加的关于缩小的材料,所以你自己整理了那部分。那挺好的。

至于服务器上的过期标头和 gzip,虽然您可以直接在节点中执行此操作,但我们不会!一般来说,我们从不让节点直接与最终用户对话。相反,我们使用 nginx 作为反向代理,它为我们提供负载平衡并允许我们直接传递静态文件。nginx 是用 C/C++ 编写的,在这方面速度更快。gzip 和 TLS 的实现也经过了实战考验。无需让 javascript 做它不擅长的事情。

我们通常使用mechanic来配置 nginx ,我们创建它是为了使用一些命令来管理 nginx,而不是手动编写配置文件。我们的标准配方包括 gzip 和 expires 标头。

但是,这是它创建的 nginx 配置文件的注释版本。您会看到它涵盖了静态文件的负载平衡、gzip 和更长的过期时间。

# load balance across 4 instances of apostrophe listening on different ports
upstream upstream-example {
  server localhost:3000;
  server localhost:3001;
  server localhost:3002;
  server localhost:3003;
}

server {
  # gzip transfer encoding
  gzip on;
  gzip_types text/css text/javascript image/svg+xml
    application/vnd.ms-fontobject application/x-font-ttf
    application/x-javascript application/javascript;

  listen *:80;

  server_name www.example.com example.com;

  client_max_body_size 32M;

  access_log /var/log/nginx/example.access.log;
  error_log /var/log/nginx/example.error.log;

   # reverse proxy: pass requests to nodejs backends        
  location @proxy-example-80 {
    proxy_pass http://upstream-example;

    proxy_next_upstream error timeout invalid_header http_500 http_502
  http_503 http_504;
    proxy_redirect off;
    proxy_buffering off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
  }

  # Deliver static files directly if they exist matching the URL,
  # if not proxy to node
  location / {
    root /opt/stagecoach/apps/example/current/public/;
    try_files $uri @proxy-example-80;
    # Expires header: 7-day lifetime for static files
    expires 7d;
  }
}
于 2016-11-05T14:52:42.083 回答