Невозможно активировать сжатие текста на сервере Apache 2.4 - PullRequest
0 голосов
/ 12 октября 2019

Я ищу много сообщений об активации сжатия на серверах Apache 2.4.10. Ни одно из решений не работает для меня. У меня больше нет идей.

Я активировал все необходимые модули (здесь распечатка apachectl -M):

Loaded Modules:
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 core_module (static)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 expires_module (shared)
 filter_module (shared)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 perl_module (shared)
 php7_module (shared)
 proxy_http_module (shared)
 proxy_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 so_module (static)
 socache_shmcb_module (shared)
 ssl_module (shared)
 status_module (shared)
 unixd_module (static)
 version_module (static)
 watchdog_module (static)

Здесь мой файл .htaccess:

# Deflate Compression by MimeType
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/atom_xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/x-shockwave-flash
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE application/x-font-ttf
    AddOutputFilterByType DEFLATE application/x-font-opentype
    AddOutputFilterByType DEFLATE application/x-font-woff
    AddOutputFilterByType DEFLATE font/ttf
    AddOutputFilterByType DEFLATE font/otf
    AddOutputFilterByType DEFLATE font/woff
</IfModule>

# Deflate Compression by FileType
<IfModule mod_deflate.c>
    <FilesMatch "\.(js|jpg|jpeg|gif|png|svg|css|eot|ttf|otf|woff)$">
        ExpiresActive on
        ExpiresDefault "access plus 1 month"
        SetOutputFilter DEFLATE
    </FilesMatch>
</IfModule>

# new Deflate Compression
<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/javascript application/x-javascript application/x-httpd-php application/x-font-ttf application/x-font-opentype application/x-font-woff font/ttf font/otf font/woff
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
</IfModule>

# GZip Compression
<IfModule mod_gzip.c>
    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-javascript.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

# turns cache on for 1 month
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
    ExpiresByType application/x-font-ttf "access plus 1 year"
    ExpiresByType application/x-font-opentype "access plus 1 year"
    ExpiresByType application/x-font-woff "access plus 1 year"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 month"
</IfModule>

<IfModule mod_headers.c>
    <filesmatch "\\.(ico|jpe?g|png|gif|svg|swf|eot|ttf|woff)$">
        Header set Cache-Control "max-age=2592000, public"
    </filesmatch>
    <filesmatch "\\.(css)$">
        Header set Cache-Control "max-age=604800, public"
    </filesmatch>
    <filesmatch "\\.(js)$">
        Header set Cache-Control "max-age=604800, public"
    </filesmatch>
</IfModule>

Здесь мой файл 000-default.conf:

<VirtualHost *:443>
    ServerName www.xxxxxxxxxxx.com
    ServerAlias xxxxxxxxxxx.com

    SSLEngine on
    SSLProtocol TLSv1.2
    SSLCertificateFile /var/ssl/xxxxxxxxxxx.crt
    SSLCertificateKeyFile /var/ssl/xxxxxxxxxxx.key
    SSLCACertificateFile /var/ssl/Intermediate_CA_Bundle.crt

    DocumentRoot /var/www/public

    <Location />
        RewriteEngine On

        #
        # circumvent relative linking
        #
        RewriteCond %{REQUEST_URI} ^(.*)/([^/]+)/favicon.ico$ [NC]
        RewriteRule ^(.*)/favicon.ico$          /favicon.ico [R=301,L]

        RewriteCond %{REQUEST_URI} ^(.*)/([^/]+)/assets/(.*)$ [NC,OR]
        RewriteCond %{REQUEST_URI} ^(.*)/([^/]+)/images/(.*)$ [NC,OR]
        RewriteCond %{REQUEST_URI} ^(.*)/([^/]+)/css/(.*)$ [NC,OR]
        RewriteCond %{REQUEST_URI} ^(.*)/([^/]+)/js/(.*)$ [NC,OR]
        RewriteCond %{REQUEST_URI} ^(.*)/([^/]+)/fonts/(.*)$ [NC]
        RewriteRule ^(.*)/([^/]+)/([^/]+)$      /$2/$3 [R=301,L]

        RewriteCond %{REQUEST_FILENAME} -s [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
        RewriteRule ^.*$ index.php [NC,L]
    </Location>
</VirtualHost>

AddDefaultCharset utf-8

ScriptAlias /cgi-bin/ /var/www/cgi-bin/

<Directory /var/www/>
    Options -Indexes +FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

<Files "*.inc">
    Require all denied
</Files>

ErrorDocument 404 /404.html

Кто-нибудь может помочь получить сжатие текста / html, работающее на моем сервере apache? Большое спасибо.

1 Ответ

0 голосов
/ 14 октября 2019

Чтобы включить сжатие через SSL, необходимо использовать SSLCompression on в конфигурации apache. Но по соображениям безопасности openssl-lib собирается без поддержки сжатия. Для включения сжатия SSL необходимо создать собственную библиотеку openssl. Здесь больше информации: https://security.stackexchange.com/questions/137182/enabling-sslcompression-in-apache

...