瀏覽代碼

[Nginx] Add compression, change expires

andryyy 6 年之前
父節點
當前提交
60f9968134
共有 1 個文件被更改,包括 20 次插入10 次删除
  1. 20 10
      data/conf/nginx/site.conf

+ 20 - 10
data/conf/nginx/site.conf

@@ -7,15 +7,6 @@ map $http_x_forwarded_proto $client_req_scheme {
      https https;
 }
 
-map $sent_http_content_type $expires {
-        default off;
-        text/html off;
-        text/css 1d;
-        application/javascript 1d;
-        application/json off;
-        image/png       1d;
-}
-
 server {
   include /etc/nginx/mime.types;
   charset utf-8;
@@ -47,6 +38,17 @@ server {
   include /etc/nginx/conf.d/listen_ssl.active;
   include /etc/nginx/conf.d/server_name.active;
 
+  gzip on;
+  gzip_disable "msie6";
+
+  gzip_vary on;
+  gzip_proxied any;
+  gzip_comp_level 6;
+  gzip_buffers 16 8k;
+  gzip_http_version 1.1;
+  gzip_min_length 256;
+  gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
+
   error_log  /var/log/nginx/error.log;
   access_log /var/log/nginx/access.log;
   absolute_redirect off;
@@ -105,7 +107,6 @@ server {
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_redirect off;
-    expires $expires;
   }
 
   location ~* ^/Autodiscover/Autodiscover.xml {
@@ -185,5 +186,14 @@ server {
     alias /usr/lib/GNUstep/SOGo/$1.SOGo/Resources/$2;
   }
 
+  location ~* \.(?:css|js|ico|woff|eot|svg|ttf|otf|png|gif|jpe?g) {
+    access_log off;
+    add_header Cache-Control public;
+  }
+
+  location ~* \.(?:css|js|woff|eot|svg|ttf|otf|png|gif|jpe?g) {
+    expires max;
+  }
+
   include /etc/nginx/conf.d/site.*.custom;
 }