以下内容为原创,转载请注明出处!
最近用https://gtmetrix.com/给朋友的国外网站做检测,发现在资源缓存GRADE为0,所以打算记录下怎么用apache2处理静态资源缓存问题。
详细配置
<VirtualHost *:80>
WSGIScriptAlias / /home/gs/project/liuQi/liuQi/wsgi.py
WSGIDaemonProcess gs processes=2 threads=15 display-name=%{GROUP} python-path=/home/gs/project/liuQi:/home/gs/env/gs_env/lib/python3.5/site-packages
WSGIProcessGroup gs
Alias /static/ /home/gs/project/liuQi/static/
Alias /media/ /home/gs/project/liuQi/media/
ServerName www.xxxx.com
ServerAlias xxxx.com
DocumentRoot /home/gs/project/
#启动mod_expires模块
ExpiresActive On
# Images
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 days"
ExpiresByType image/png "access plus 1 days"
ExpiresByType image/webp "access plus 1 days"
ExpiresByType image/svg+xml "access plus 1 days"
ExpiresByType image/x-icon "access plus 1 days"
# Video
ExpiresByType video/mp4 "access plus 1 days"
ExpiresByType video/mpeg "access plus 1 days"
# CSS, JavaScript
ExpiresByType text/css "access plus 1 days"
ExpiresByType text/javascript "access plus 1 days"
ExpiresByType application/javascript "access plus 1 days"
# 配置mod_headers模块
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|woff|js|css|swf)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
<Directory /home/gs/project/liuQi/static>
Require all granted
</Directory>
<Directory /home/gs/project/liuQi/media>
Require all granted
</Directory>
<Directory /home/gs/project/liuQi>
<Files wsgi.py>
Require all granted
</Files>
</Directory>激活模块
a2enmod headers a2enmod expires
启动服务
server apache2 reload
服务器部署请参照:https://www.520pf.cn/article/22.html
负载均衡,会话保持请参照:https://www.520pf.cn/article/162.html
ssl证书配置,请参照:https://www.520pf.cn/article/102.html