Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
754 views
in Technique[技术] by (71.8m points)

recommended nginx configuration for meteor

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

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?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.

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

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.

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;

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

update 9/17/2014:

Updated the paths for meteor 0.9.2.1


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...