我有对JavaScript文件expires
头这是由PHP产生的问题过期了nginx的与JavaScript文件(由PHP动态生成)
该网站有两种类型的JavaScript文件。一部分是静态JavaScript文件,另一部分是由PHP动态生成的。
的conf没有Expires头
这里没有expires
头文件(所有文件返回HTTP 200
)加入到.js
文件
location/{
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
include /var/ini/nginx/fastcgi.conf;
fastcgi_pass php;
fastcgi_param SCRIPT_FILENAME /var/www/index.php;
}
的conf与Expires头
当.js
文件添加地点那么所有动态生成的文件返回HTTP 404
location/{
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
include /var/ini/nginx/fastcgi.conf;
fastcgi_pass php;
fastcgi_param SCRIPT_FILENAME /var/www/dyndev.dk/public/secure/index.php;
}
location ~ \.(js|css)$ {
expires 1y;
add_header Cache-Control "public";
}
如何使用expires
头文件处理静态和动态生成的.js
文件?
所有动态genereated JavaScript文件被命名为*-php.js
文件结构
/var/www/public/index.php # All none-static file requests are pointed to index.php
/var/www/public/js/main.js # Static files
/var/www/js-dynamically_generated.php # This file is outside the public www, but is routed by PHP since the file doesn't exists inside the public /js
PHP路由
www.example.com/ -> index.php
www.example.com/js -> static content
www.example.com/js/dynamically_generated-php.js -> js-dynamically_generated.php
如果你用php创建js为什么你不用PHP函数添加标题? – Kiyan
已更新我的问题 – clarkk