![ExpiresByType “访问加 1 个月”导致 1 年过期标头](https://linux22.com/image/728538/ExpiresByType%20%E2%80%9C%E8%AE%BF%E9%97%AE%E5%8A%A0%201%20%E4%B8%AA%E6%9C%88%E2%80%9D%E5%AF%BC%E8%87%B4%201%20%E5%B9%B4%E8%BF%87%E6%9C%9F%E6%A0%87%E5%A4%B4.png)
我已经通过以下设置实现了资源到期
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
随着 a2dismod 过期,正如预期的那样,我没有 Expires 标头:
wget --server-response --no-check-certificate https://sandbox.trinityp3.com/wp-includes/js/jquery/jquery.js?ver=1.12.4
--2018-10-17 07:57:09-- https://sandbox.trinityp3.com/wp-includes/js/jquery/jquery.js?ver=1.12.4
Resolving sandbox.trinityp3.com (sandbox.trinityp3.com)... 52.77.97.226
Connecting to sandbox.trinityp3.com (sandbox.trinityp3.com)|52.77.97.226|:443... connected.
WARNING: cannot verify sandbox.trinityp3.com's certificate, issued by ‘[email protected],CN=sandbox.trinityp3.com,O=Internet Widgits Pty Ltd,ST=Some-State,C=AU’:
Self-signed certificate encountered.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Date: Tue, 16 Oct 2018 18:57:10 GMT
Server: Apache/2.4.10 (Ubuntu)
Last-Modified: Tue, 06 Sep 2016 02:32:13 GMT
Accept-Ranges: bytes
Content-Length: 97184
Vary: Accept-Encoding
Access-Control-Allow-Origin: *
Referrer-Policy:
Cache-Control: max-age=604800, public
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/x-javascript
但是使用 a2enmod expires 时,我收到了 1 年过期的响应
wget --server-response --no-check-certificate https://sandbox.trinityp3.com/wp-includes/js/jquery/jquery.js?ver=1.12.4
--2018-10-17 08:01:26-- https://sandbox.trinityp3.com/wp-includes/js/jquery/jquery.js?ver=1.12.4
Resolving sandbox.trinityp3.com (sandbox.trinityp3.com)... 52.77.97.226
Connecting to sandbox.trinityp3.com (sandbox.trinityp3.com)|52.77.97.226|:443... connected.
WARNING: cannot verify sandbox.trinityp3.com's certificate, issued by ‘[email protected],CN=sandbox.trinityp3.com,O=Internet Widgits Pty Ltd,ST=Some-State,C=AU’:
Self-signed certificate encountered.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Date: Tue, 16 Oct 2018 19:01:27 GMT
Server: Apache/2.4.10 (Ubuntu)
Last-Modified: Tue, 06 Sep 2016 02:32:13 GMT
Accept-Ranges: bytes
Content-Length: 97184
Vary: Accept-Encoding
Cache-Control: max-age=604800, public
Expires: Wed, 16 Oct 2019 19:01:27 GMT
Access-Control-Allow-Origin: *
Referrer-Policy:
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/x-javascript
我还运行了 grep 来查找任何其他过期语句,但是没有。
添加 ExpiresByType application/x-javascript 后问题仍然存在。会不会与 deflate 发生冲突?
ubuntu@sandbox:/etc/apache2$ grep -r application/x-javascript *
mods-available/deflate.conf: AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript
sites-available/710-tp3-au-www-sandbox.conf: ExpiresByType application/x-javascript "access plus 1 month"
sites-available/710-tp3-au-www-sandbox.conf: ExpiresByType application/x-javascript "access plus 1 month"
答案1
您没有针对您的文件提供服务的ExpiresByType
规则。application/x-javascript
Content-Type
.js