我在 debian 上运行 apache 2.2.22。
我尝试在此服务器上启用放气,但无论我做什么,响应都不会放气。
以下是已启用模块的列表:
apache2ctl -M
Loaded Modules:
core_module (static)
log_config_module (static)
logio_module (static)
version_module (static)
mpm_prefork_module (static)
http_module (static)
so_module (static)
alias_module (shared)
auth_basic_module (shared)
authn_file_module (shared)
authz_default_module (shared)
authz_groupfile_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
cgi_module (shared)
deflate_module (shared)
dir_module (shared)
env_module (shared)
expires_module (shared)
filter_module (shared)
headers_module (shared)
mime_module (shared)
negotiation_module (shared)
pagespeed_module (shared)
php5_module (shared)
reqtimeout_module (shared)
rewrite_module (shared)
setenvif_module (shared)
status_module (shared)
Syntax OK
这是我的虚拟主机:
<VirtualHost 148.251.236.145:80>
ServerName www.tren.at
ServerAlias tren.at *.tren.at
ServerAdmin [email protected]
DocumentRoot /var/www/tren
ServerSignature on
LogLevel info
ErrorLog /var/log/apache2/error-tren.log
CustomLog /var/log/apache2/access-tren.log combined
RewriteLog /var/log/apache2/rewrite-tren.log
RewriteLogLevel 3
AllowEncodedSlashes on
<Directory /var/www/tren/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
DirectoryIndex index.php
</Directory>
<Directory /var/www/tren/images/>
<FilesMatch "(?i)\.((?!.*(jpg|jpeg|png|gif|bmp)).*)$">
Order Deny,Allow
Deny from All
</FilesMatch>
</Directory>
<Directory /var/www/tren/cache/>
<FilesMatch "(?i)\.((?!.*(jpg|jpeg|png|gif|bmp)).*)$">
Order Deny,Allow
Deny from All
</FilesMatch>
</Directory>
</VirtualHost>
最后是我的 .htaccess
Options -MultiViews
Options +FollowSymLinks
# Enable GZIP
<IfModule mod_deflate.c>
# HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
<IfModule filter_module>
FilterDeclare COMPRESS
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject
FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf
FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype
FilterChain COMPRESS
FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no
</IfModule>
<IfModule !mod_filter.c>
# Legacy versions of Apache
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml
AddOutputFilterByType DEFLATE application/atom+xml
AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font-ttf font/opentype
</IfModule>
</IfModule>
# Expires Headers - 2678400s = 31 days
<ifmodule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 7200 seconds"
ExpiresByType image/gif "access plus 2678400 seconds"
ExpiresByType image/jpeg "access plus 2678400 seconds"
ExpiresByType image/png "access plus 2678400 seconds"
ExpiresByType text/css "access plus 518400 seconds"
ExpiresByType text/javascript "access plus 2678400 seconds"
ExpiresByType application/x-javascript "access plus 2678400 seconds"
</ifmodule>
# Cache Headers
<ifmodule mod_headers.c>
# Cache specified files for 31 days
<filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
Header set Cache-Control "max-age=2678400, public"
</filesmatch>
# Cache HTML files for a couple hours
<filesmatch "\.(html|htm)$">
Header set Cache-Control "max-age=7200, private, must-revalidate"
</filesmatch>
# Cache PDFs for a day
<filesmatch "\.(pdf)$">
Header set Cache-Control "max-age=86400, public"
</filesmatch>
# Cache Javascripts for 31 days
<filesmatch "\.(js)$">
Header set Cache-Control "max-age=2678400, private"
</filesmatch>
</ifmodule>
RewriteEngine on
RewriteBase /
RewriteRule . - [E=no-gzip:1]
RewriteRule ^(.*)/product/([0-9]+)/(.*)$ product_info.php/products_id/$2/$3 [QSA,L]
RewriteRule ^(.*)/product/([0-9]+)$ product_info.php?products_id=$2 [QSA,L]
RewriteRule ^(.*)/cat/([0-9,_]+)/(.*)$ index.php/cPath/$2/$3 [QSA,L]
RewriteRule ^(.*)/cat/([0-9,_]+)$ index.php?cPath=$2 [QSA,L]
## Redirect to www
#
RewriteCond %{http_host} ^tren.at [nc]
RewriteRule ^(.*)$ http://www.tren.at/$1 [r=301,nc]
如果我现在尝试从该站点获取一个简单的 html 文件,它不会被压缩。php输出也会发生同样的情况:
curl --compressed -I http://www.tren.at/test.html
HTTP/1.1 200 OK
Date: Wed, 22 Apr 2015 10:37:57 GMT
Server: Apache/2.2.22 (Debian)
Last-Modified: Wed, 12 Nov 2014 10:34:38 GMT
Accept-Ranges: none
Cache-Control: max-age=7200, private, must-revalidate
Expires: Wed, 22 Apr 2015 12:37:57 GMT
Content-Length: 322
Content-Type: text/html
我已经在 php.ini 中禁用了 output_buffering 和 zlib.output_compression。
我的配置中某处有错误吗?我还能尝试什么来查找问题/解决问题?
编辑:
有趣的是,当我在配置中出现语法错误时,我得到的 500 错误被压缩了!
我有以下内容,它有效,并且看起来与您的完全不同。如果您将配置简化为大致这样会怎样?
另外,如果可以避免这样做,
Vary: Accept-Encoding
请不要忘记使用。您可能还想在传入的请求标头到达您的缓存之前调整它们(如果有的话)。否则,您将获得非常垃圾的缓存命中率,因为您将为所有不同的压缩技术和所有不同的用户代理字符串缓存 40 多种不同的表示。Vary: User-Agent
Accept-Encoding
这是我将使用反向代理来实现这一点的内容。
MASHED 主要是为了提醒我标题已被编辑。
罪魁祸首是重写模式中的一条规则:
这是我忘记的旧配置的一部分。