我是 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;
}
}