2014-11-03 53 views
1

我使用nginx和php-fpm,但无法获得gzip来压缩任何东西。服务器是带编译nginx的Centos 6.5,命令如下: - sbin-path =/usr/sbin/nginx --with-http_stub_status_module --conf-path = /etc/nginx/nginx.conf --pid-path =/var /运行/ nginx.pid --error-log-path =/var/log/nginx/error.log --http-log-path =/var/log/nginx/access.log --user = nginx --with- http_gzip_static_moduleNginx和gzip无法正常工作。我错在哪里

这里是nginx.conf:

include  /etc/nginx/mime.types; 
default_type application/octet-stream; 
access_log off; 
log_not_found off; 
sendfile  on; 
tcp_nopush  on; 
tcp_nodelay on; 
client_body_timeout 30; 
client_header_timeout 30; 
keepalive_timeout  45; 
send_timeout   30; 
reset_timedout_connection on; 
output_buffers 1 8M; 
gzip    on; 
gzip_static  on; 
gzip_buffers  16 8k; 
gzip_comp_level 5; 
gzip_http_version 1.1; 
gzip_min_length 2; 
gzip_types  text/plain application/xml text/css text/js text/xml application/x-javascript text/javascript application/json application/xml+rss; 
gzip_vary   on; 
gzip_proxied any; 
#gzip_disable "MSIE [1-6]\.(?!.*SV1)"; 
gzip_disable msie6; 
server_names_hash_max_size 1024; 
server_names_hash_bucket_size 128; 
open_file_cache max=20000 inactive=20s; 
open_file_cache_valid 30s; 
open_file_cache_min_uses 2; 
open_file_cache_errors on; 
client_body_buffer_size 1024k; 
fastcgi_buffers 64 64k; 
include /etc/nginx/conf.d/domains/*.conf; 

这里是domain.conf:

server { 
    listen xx.xx.xx.xx:80; 
    server_name xxxxxxxx.com; 
    if ($host ~* ^(?!(www|cdn)\.)) { 
     rewrite .* $scheme://www.$host$request_uri permanent; 
    } 
    index index.php; 
    charset utf-8;. 
    if ($request_uri ~* "^(.*(?<!expert)/)index\.php$") { 
     return 301 $1; 
    } 
    root /home/ftpaccess/xxxxxxx/www; 
    location ~* ^.+\.(txt|js|css|doc|xls|pdf|ppt|rtf|jpg|jpeg|gif|bmp|ico|zip|tgz|gz|bz2|exe|tar|wav|avi|flv|mpg|mpeg|mp4|mp3|png)$ { 
     expires 720h; 
     add_header Pragma public; 
     add_header Cache-Control "public"; 
    } 
    location ~ /\.ht { 
     deny all; 
    } 
    location = /favicon.ico { access_log off; log_not_found off; } 
    location = /robots.txt { access_log off; log_not_found off; allow all;} 
    location = /apple-touch-icon.png { access_log off; log_not_found off; } 
    location = /apple-touch-icon-precomposed.png { access_log off; log_not_found off; } 
    error_page 404 /404.php; 
    include /etc/nginx/conf.d/redirect/xxxxxx.conf; 
    location ~ \.php$ { 
     include /etc/nginx/php.conf; 
     include  /etc/nginx/fastcgi_params; 
    } 
} 

和php.conf:

fastcgi_split_path_info ^(.+\.php)(/.+)$; 
try_files $uri =404; 
fastcgi_pass unix:/var/run/php5-fpm.sock; 
fastcgi_index index.php; 
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
fastcgi_read_timeout 300; 

卷曲-I -H '接受编码:gzip,放气' http://www.xxxxxx.com响应:

HTTP/1.1 200 OK 
Server: nginx/1.6.2 
Date: Mon, 03 Nov 2014 22:14:23 GMT 
Content-Type: text/html; charset: iso-8859-1 
Connection: keep-alive 
Set-Cookie: PHPSESSID=0pi4o2i83gvof758gep5nc01m5; path=/ 
Expires: Thu, 19 Nov 1981 08:52:00 GMT 
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 
Pragma: no-cache 

卷曲-I -H '接受编码:gzip,放气' http://www.xxxxxxx.com/js/pop.js响应:

HTTP/1.1 200 OK 
Server: nginx/1.6.2 
Date: Mon, 03 Nov 2014 22:15:21 GMT 
Content-Type: application/javascript 
Content-Length: 5241 
Last-Modified: Mon, 03 Nov 2014 21:21:28 GMT 
Connection: keep-alive 
Expires: Wed, 03 Dec 2014 22:15:21 GMT 
Cache-Control: max-age=2592000 
Pragma: public 
Cache-Control: public 
Accept-Ranges: bytes 

我在哪里做错了,如何解决?尝试几乎所有的东西,不能成功。

回答

1

您的gzip_types不包含您引用的类型。

正如你所看到的,下面的类型是由你的配置涵盖: text/plain application/xml text/css text/js text/xml application/x-javascript text/javascript application/json application/xml+rss但你同时引用text/javascriptapplication/javascript

相关问题