2017-05-04 59 views
0

我有一個Rails應用程序,所以當我進行預編譯時,也會爲我編譯gzip資產。我用下面的Apache的配置,以滿足了gzip的資產:使用Apache通過HTTPS/SSL提供gzip資產

<Location /assets/> 
    RewriteEngine on 

    # Make sure the browser supports gzip encoding before we send it 
    # without it, Content-Type will be "application/x-gzip" 

    RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b 
    RewriteCond %{REQUEST_FILENAME}.gz -s 
    RewriteRule ^(.+) $1.gz [L] 
</Location> 

# Also add a content-encoding header to tell the browser to decompress 

<FilesMatch \.css\.gz$> 
    ForceType text/css 
    Header set Content-Encoding gzip 
</FilesMatch> 

<FilesMatch \.js\.gz$> 
    ForceType text/javascript 
    Header set Content-Encoding gzip 
</FilesMatch> 

不過,我注意到這不會對https SSL站點工作。它在http網站上工作。我如何讓Apache在https上提供gzip資源?我不需要使用mod_deflate,因爲當我編譯我的Rails資產時,我的gzip資源已經編譯完成。

+0

此配置坐在哪裏?我會懷疑你有兩個不同的虛擬主機SSL和非SSL,這隻適用於非SSL虛擬主機。 – Capsule

+0

哦,這可能只適用於非SSL的。該配置位於''中。我是否也應該將它複製到''? –

+0

啊,這是問題所在。我已將配置複製到443虛擬主機,並且它可以正常工作。謝謝! –

回答

0

由於@Capsule在評論中提到,除了<VirtualHost *:80>之外,我還需要把gzip config的大塊變成<VirtualHost _default_:443>

+0

我只是把它放在'.htaccess'文件中,所以如果可以的話,你不要複製規則。 – Capsule

+0

或者只是將非SSL重定向到SSL,並且只有SSL vhost中有一個配置 – Capsule

相關問題