Php 如何在nginx中向重写的资源添加头?
我正在使用cakephp,我的一些资产(javascript和css)需要重写,例如:Php 如何在nginx中向重写的资源添加头?,php,cakephp,nginx,Php,Cakephp,Nginx,我正在使用cakephp,我的一些资产(javascript和css)需要重写,例如: location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { try_files $uri $uri/ /index.php?$uri\&$args; expires 1M; access_log off; add_header Pragma "public"; add_header Cache-Contr
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
try_files $uri $uri/ /index.php?$uri\&$args;
expires 1M;
access_log off;
add_header Pragma "public";
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
然而,当我重写时,我在这个位置块中添加的头丢失了。在Cakephp中重写需要index.php文件,因此上面的try_files指令最终将我带到以下位置:
location ~* \.(?:php)$ { ... }
然后,资源只接收在该位置设置的头。这不是我想要的-我希望能够重新连接资源并应用正确的标题。。。尽管我在网上到处寻找,但我还是找不到如何防止对资源标题的更改进行重写。应该通过将webroot设置为文档根来工作 检查下面的配置
root /home/your_user/your_app/webroot;
index index.html index.htm index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
向资源添加标题
location ~* \.(type|type1|type2|type3)$ {
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
}
我的文档根目录已设置为webroot。它仍然不允许我在重写资产时指定标题。