我有以下 nginx 配置:
server {
listen 8080;
root /site_root/web;
index index.html;
server_name www.mysite.com;
location / {
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
# add headers to static files
location ~* \.(?:ico|css|js|gif|jpe?g|png|svg|woff|ttf|eot)$ {
expires 365d;
add_header Pragma public;
add_header Cache-Control "public";
}
location ~ \.php {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS $https;
fastcgi_pass unix:/var/run/php-fpm-www.sock;
}
}
Run Code Online (Sandbox Code Playgroud)
问题 这是一个标准的 php 应用程序,带有前端控制器和一些静态资产(js/css 等)作为文件系统上的文件(为了参数,这些文件的位置是“/site_root/web/assets”)。
上述配置的目的是向这些静态文件添加“max-age”标头,以允许浏览器缓存它们。这适用于文件系统上存在的所有文件。但是我有一些动态生成的资产,需要通过 php …