apache2.conf
相反,我每次创建新的服务器环境时都必须复制粘贴以下代码以启用 Gzip 压缩和缓存过期,有没有办法通过一些 CLI 命令使它们从 Apache 本身出现?
## ENABLE GZIP
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>
## ENABLE GZIP ##
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##
更新
没有其他方法可以在/etc/apache2/apache2.conf
不粘贴或include
s 的情况下自动添加这些内容吗?
要尽可能轻松地部署配置,最好的方法是运行脚本(或运行每个命令)。
您不需要列出的所有更改。Apache2 已经与
mods-available/deflate.conf
您的类似。只需启用它即可获得 GZIP 支持。脚本将是(我称之为
a2gzip.sh
):用于
sudo ./a2gzip.sh
运行脚本。