Deployment 让NGINX为unicorn提供.gz压缩资产文件

Deployment 让NGINX为unicorn提供.gz压缩资产文件,deployment,nginx,unicorn,Deployment,Nginx,Unicorn,我想在我的nginx和unicorn中激活gzip压缩: 我在rails应用程序中的config/unicorn.rb: working_directory "/home/user/project.com/current" shared_path = '/home/user/project.com/shared' pid "#{shared_path}/pids/unicorn.pid" stderr_path "#{shared_path}/log/unicorn.log" stdout_p

我想在我的nginx和unicorn中激活gzip压缩:

我在rails应用程序中的config/unicorn.rb:

working_directory "/home/user/project.com/current"
shared_path  = '/home/user/project.com/shared'
pid "#{shared_path}/pids/unicorn.pid"
stderr_path "#{shared_path}/log/unicorn.log"
stdout_path "#{shared_path}/log/unicorn.log"
listen '/tmp/unicorn.project.sock'
worker_processes 2
timeout 30
  gzip_static on;
  expires max;
  add_header Cache-Control public;
我在rails应用程序的nginx.conf中有这个:

upstream unicorn {
 server unix:/tmp/unicorn.project.sock fail_timeout=0;
}

 server {
       listen 80 default;
       root ~/project.com/current/public;
       try_files $uri/index.html $uri @unicorn;

       location @unicorn {
                           proxy_pass http://unicorn;
                         }
 error_page 500 502 503 504 /500.html;
}
如何启用此配置,例如:

working_directory "/home/user/project.com/current"
shared_path  = '/home/user/project.com/shared'
pid "#{shared_path}/pids/unicorn.pid"
stderr_path "#{shared_path}/log/unicorn.log"
stdout_path "#{shared_path}/log/unicorn.log"
listen '/tmp/unicorn.project.sock'
worker_processes 2
timeout 30
  gzip_static on;
  expires max;
  add_header Cache-Control public;

谢谢大家!

这是我的nginx.conf中关于gzip的内容:

gzip on;
gzip_buffers 16 8k;
gzip_comp_level 9;
gzip_http_version 1.0;
gzip_min_length 0;
gzip_types text/plain text/css image/x-icon image/png image/jpg image/jpeg text/js text/php application/javascript application/x-javascript;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable     "MSIE [1-6]\.";
您还可以记录gzip压缩:

log_format main
        '$remote_addr - $remote_user [$time_local] '
        '"$request" $status $bytes_sent '
        '"$http_referer" "$http_user_agent" '
        '"$gzip_ratio"';

这是我的nginx.conf中针对gzip的内容:

gzip on;
gzip_buffers 16 8k;
gzip_comp_level 9;
gzip_http_version 1.0;
gzip_min_length 0;
gzip_types text/plain text/css image/x-icon image/png image/jpg image/jpeg text/js text/php application/javascript application/x-javascript;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable     "MSIE [1-6]\.";
您还可以记录gzip压缩:

log_format main
        '$remote_addr - $remote_user [$time_local] '
        '"$request" $status $bytes_sent '
        '"$http_referer" "$http_user_agent" '
        '"$gzip_ratio"';

添加到配置中的
server{}
块:

location ~ ^/(assets)/  {
  root /path/to/public;
  gzip_static on; # to serve pre-gzipped version
  expires max;
  add_header Cache-Control public;
}

签出以获取更多信息。

添加到配置中的
服务器{}
块:

location ~ ^/(assets)/  {
  root /path/to/public;
  gzip_static on; # to serve pre-gzipped version
  expires max;
  add_header Cache-Control public;
}
查看更多信息