如何访问电脑图片:

1、当前端部署在nginx中时,要想访问图片,需要通过nginx配置虚拟主机来访问本地电脑图片。

参考:https://www.cnblogs.com/zwh0910/p/15400883.html

2、当时springboot项目时,配置静态文件映射来实现访问本地电脑图片

参考:https://www.cnblogs.com/zwh0910/p/15625422.html

3、当前端部署在tomcat中时,要想访问图片,则需要在server.xml中进行配置

参考本文:https://www.cnblogs.com/zwh0910/p/15724482.html

步骤:

1、在server.xml中配置

<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->
        <Context path="/localimg" docBase="d://upload/"></Context>
        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>

该配置的作用:当浏览器访问/localimg时,就会映射到本地电脑的d://upload。

2、启动tomcat

端口为8081

3、浏览器访问本地电脑D:\upload\20211222目录下的图片

http://localhost:8081/localimg/20211222/2d963bb1-b8a9-4407-aeab-c4bd26a4569c.jpg

 

posted on 2021-12-23 17:31  周文豪  阅读(550)  评论(0编辑  收藏  举报