背景:有時候我一些資源(.js .css etc.)等不想訪問我本地的,我想重定向到其他 URL
解決:直接修改 nginx 的配置文件 conf,添加下面的代碼
#avoid processing of calls to unexisting static files by yii location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar|mp3|wav)$ { access_log /log/nginx/XXXXXXX.assets.access.log;
#root "C:/you project/assets";#這里可以指向你本地 rewrite ^/temp(.*) /temp$1 break; rewrite ^(.*) https://cdn.assets.com/aeeest$1 permanent; }
-access_log:訪問日志
-root:一般指向本地靜態資源路徑
-rewrite:重定向到指定路徑