2016-02-12 32 views
0

我使用CakePHP和我的一些資產(JavaScript的& CSS)的要求被改寫 - 例如:如何將頭添加到nginx中的重寫資源?

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)$ { ... } 

的資源,然後只接收頭在該位置設置。這不是我想要的 - 我希望能夠重新調整資產並應用正確的標題......儘管在網上無處不在,我無法找到如何防止重寫改變資源的標題。

回答

0

應該將您的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'; 
} 

http://nginx.org/en/docs/http/ngx_http_headers_module.html

+0

我的文檔根已被設置爲Web根目錄。當資產被重寫時,它仍然不允許我指定標題。 – user1658296