使用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就可以访问到图片。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM