不實用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就可以訪問到圖片。

