2012-03-21 71 views
1

我想激活gzip壓縮在我的Nginx和麒麟的.gz壓縮資源文件:獲取NGINX服務與麒麟

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 

配置/ unicorn.rb有這個在我的Rails應用程序

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

我怎樣才能啓用此配置某物像:

gzip_static on; 
    expires max; 
    add_header Cache-Control public; 

謝謝!

回答

5

添加到server { }塊在你的配置:

​​

結帳Rails guides瞭解更多信息。

+0

謝謝它的正確性:D – hyperrjas 2012-03-22 17:18:35

1

這是我在我的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"';