nginx 资源重定向

背景:有时候我一些资源(.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:重定向到指定路径

原文地址:https://www.cnblogs.com/lyc94620/p/9963948.html