Nginx搭建后,图片存储在Tomcat上,前端无法回显图片问题

 一、NginxTomcat连接搭建的环境,Nginx设置了前端的访问路径为

  (1)前端代码配置:
        

1 root  /usr/local/nginx/html;
2 index index.html index.htm;
View Code

  (2)root   访问文件的根目录,默认nginx一起动

     一访问http://127.0.0.1 就会先跳到/usr/local/nginx/html/dist/目录下查找,目录下的html文件。

  (3)但是,当后端的接口实现文件上传后前端展示,就会发生展示不出来图片到页面上,并且日志error报错

/usr/local/nginx/html/dist/easy/companyInfo/queryCompany/1.jgp" failed (13: Permission denied) while reading upstream, client:192.168.1.106,server:localhost,request:"GET/1.jpg HTTP/1.1", host:"192.168.1.107"

  主要是前后端路径不统一,nginx启动后自动跳转到root设置的目录下找静态资源,加了强链接就将这个一起放到root目录下查找解决方案.

      (4) 一个解决方案,建立软连接

sudo ln -s /usr/tomcat-customer/webapps/easy/ easy

     (5)这样配置好的前端Nginx目录层级就如图所示:
 

     (6)这样Nginx就可以访问到Tomcat下存储的图片了

 

原文地址:https://www.cnblogs.com/liuyangfirst/p/8257623.html