不实用 Nginx 的时候我们会使用虚拟路径来配置:
在 tomcat 下的 conf/server.xml 中增加一个代码 在 <Host></Host > 中间
如下:
<!-- 增加的 --path="/ 虚拟名" docBase="虚拟路径" ->
<Context path="/upload" docBase="D:\pic\" reloadable="true"></Context>
配置好以后, 在 JSP 文件中为:
<img src="/upload/110.jpg">
图片就显示出来了
nginx.conf 文件主要内容如下
- upstream myhost {
- server localhost:8080 weight=6; #权重, 我这里随便写的
- server localhost:8091 weight=4;
- }
- server {
- listen 80;
- server_name localhost;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- location / {
- root html;
- index index.html index.htm;
- proxy_pass http://myhost;
- }
- location /res/ {
- alias D:/pic/;
- }
- }
D:/pic / 目录下是我图片路径, 例如 D:/pic / 下有一张名为 100.jpg 的图片, 现在只需要访问 http://localhost/res/110.jpg 就可以访问到图片
来源: http://www.bubuko.com/infodetail-2524184.html