首页 新闻 赞助 找找看

nginx无法代理多级目录的静态资源

0
悬赏园豆:10 [已解决问题] 解决于 2022-12-15 17:19

nginx代理静态目录后,无法访问静态目录下的多级目录的资源。

操作环境、软件版本等信息

环境使用docker + nginx;
nginx版本:1.22.0

尝试过的解决方法

尝试一:访问user.png => 404

 location / {
         root /app/docker/statics/web;
         try_files $uri $uri/ /index.html;
         index index.html index.htm;
 }
 location /applet {
       root /app/docker/statics;
       index index.html;
}

尝试二:访问user.png => 404

location / {
         root /app/docker/statics/web;
         try_files $uri $uri/ /index.html;
         index index.html index.htm;
 }
 location /applet {
       alias /app/docker/statics/applet;
}

请问图片位于静态目录的不同路径下,nginx是如何配置的呢?

混沌之灵的主页 混沌之灵 | 初学一级 | 园豆:193
提问于:2022-12-15 15:48
< >
分享
最佳答案
0

可以试试 rewrite

location /applet {
  rewrite ^(.*)$ app/docker/statics$1;
}
收获园豆:10
dudu | 高人七级 |园豆:31075 | 2022-12-15 16:21

试了下这个配置,发现路径匹配到 / 的location。不过注释掉rewrite,再还原成alias的写法的时候,图片居然神奇的能访问到了。。。一下子确定不了是什么原因导致的了,至少问题已解决,感谢大大的支持~~

混沌之灵 | 园豆:193 (初学一级) | 2022-12-15 17:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册