您当前的位置: 首页 >  ar

彭世瑜

暂无认证

  • 1浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

SpringBoot打成war包后Tomcat无法访问静态资源问题

彭世瑜 发布时间:2020-11-23 11:43:42 ,浏览量:1

pom.xml配置了包名


	
	mobile

将mobile.war放入tomcat的webapps目录下,页面可以访问

http://localhost:8080/mobile/

不过发现静态文件都无法访问

/static/img/icon.png

静态地址是以绝对路径/static开头的,tomcat部署了多个项目,它也不知道你要访问那个项目下的静态资源,如果加上mobile 就可以访问到

/mobile/static/img/icon.png

可是我总不能在每个文件都加这么一个前缀吧

其实通过Nginx转发一下就能实现了

location / {
    proxy_pass http://127.0.0.1:8080/mobile/;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

这样一来所有路径都做了转发

/                    => /mobile/
/static/img/icon.png => /mobile/static/img/icon.png
关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.0952s