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

查看:87
本文介绍了推荐的流星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目录中可以找到此站点的任何URL,该URL包含一个斜杠,后跟40个字母数字字符+ .js或.css.静态地为这些文件提供服务,不要将它们写入访问日志,并告诉客户端它们可以永远被缓存.

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.

我将在此处维护此示例的完整版本.还值得注意的是,我正在使用最近构建的支持WebSocket的Nginx版本,如此处所述. .

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.

更新9/17/2014:

更新了流星0.9.2.1的路径

Updated the paths for meteor 0.9.2.1

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

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