为meteor推荐的nginx配置 [英] recommended nginx configuration for meteor

查看:24
本文介绍了为meteor推荐的nginx配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的流星应用的站点配置有如下所示的指令:

The site configuration for my meteor app has directives which look like the following:

server {
  listen 443;
  server_name XXX;

  ssl on;
  ssl_certificate XXX;
  ssl_certificate_key XXX;

  location / {
    proxy_pass http://localhost:3000;
    proxy_set_header X-Real-IP $remote_addr;  # http://wiki.nginx.org/HttpProxyModule
    proxy_http_version 1.1;  # recommended for keep-alive connections per http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
  }
}

我觉得我应该告诉 nginx 提供 static_cacheable 的内容并将 expires 标头设置为 max.我该怎么做呢?我还应该在此处添加其他内容吗?

I feel like I should be telling nginx to serve contents of static_cacheable and setting the expires header to max. How exactly do I go about doing that? Are there other things I should add in here?

推荐答案

虽然我不是 nginx 专家,但我觉得我现在对如何做到这一点有了更好的理解.随着我想出更多,我会更新这个答案.

Although I'm not an nginx expert, I feel like I have a much better understanding of how to do this now. As I figure out more I'll update this answer.

我原来的问题的一个可能的解决方案是:

One possible solution to my original question is this:

location ~* "^/[a-z0-9]{40}.(css|js)$" {
  root /home/ubuntu/app/bundle/programs/web.browser;
  access_log off;
  expires max;
}

其中说:可以在 web.browser 目录中找到此站点的任何包含斜杠后跟 40 个字母数字字符 + .js 或 .css 的 URL.静态服务这些文件,不要将它们写入访问日志,并告诉客户端它们可以永久缓存.

Which says: Any URL for this site containing a slash followed by 40 alphanumeric characters + .js or .css, can be found in the web.browser directory. Serve these files statically, don't write them to the access log, and tell the client that they can be cached forever.

因为主要的 css 和 js 文件在每个 bundle 操作后都是唯一命名的,所以这样做应该是安全的.

Because the the main css and js files are uniquely named after each bundle operation, this should be safe to do.

我将在此处维护此示例的完整版本.还值得注意的是,我正在使用最新版本的 nginx,它支持 WebSockets,正如 此处所述.

I'll maintain a full version of this example here. It's also worth noting that I'm using a recent build of nginx which supports WebSockets as talked about here.

最后,不要忘记在你的 nginx 配置中完全启用 gzip.我的 gzip 部分看起来像:

Finally, don't forget to fully enable gzip in your nginx config. My gzip section looks like:

gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

完成所有这些之后,我在 pagespeed 上获得了不错的分数.

After doing all that, I was able to get a decent score on pagespeed.

2014 年 9 月 17 日更新:

更新了meteor 0.9.2.1的路径

Updated the paths for meteor 0.9.2.1

这篇关于为meteor推荐的nginx配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆