使用Nginx配置资源虚拟路径

不实用Nginx的时候我们会使用虚拟路径来配置: 
在tomcat下的conf/server.xml中增加一个代码 在<Host></Host>中间 
如下: 
<!--增加的--path="/虚拟名" docBase="虚拟路径" -> 
<Context path="/upload" docBase="D:pic"  reloadable="true"></Context> 
配置好以后,在JSP文件中为: 
<img alt="" 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就可以访问到图片。

原文地址:https://www.cnblogs.com/jimmy-muyuan/p/5426515.html