若依前后端分离版,部署时通常会采用Nginx做反向代理。访问图片出现404 Not Found问题。

若依在文件上传成功后,请求访问后台地址会根据profile进行匹配,需要自己配置代理。

配置方式一:使用后端资源映射,此方式需要在Springboot项目内配置资源映射。

    # 静态资源配置方式一
    location /profile/ {
        client_max_body_size 10000m;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://localhost:8088/profile/;
    }

配置方式二:使用Nginx Alias

    location /profile/ {
    # 静态资源配置方式二:指向目录,对应后台`application.yml`中的`profile`配置目录一致
      alias /home/admin/app/attachments/;
    }

建议使用配置二。

如果这样配置了还不能访问,检查你的Nginx配置文件,注掉或删掉下述配置。

    # location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
         expires      30d;
         error_log off;
         access_log /dev/null;
    }
    
    # location ~ .*\.(js|css)?$
     {
         expires      12h;
         error_log off;
         access_log /dev/null; 
     }

Logo

快速构建 Web 应用程序

更多推荐