四诬烹、 配置動靜分離
nginx.conf配置
upstream tomcat_server{
server 10.25.39.131:8080;
server 10.25.39.132:8080;
}
server {
listen 80;
server_name www.wxvote.com;
##設(shè)置歡迎頁
location = / {
root WeiXinVote;
index index.html;
}
location ~* \.(html|css|js|gif|jpg|jpeg|mp4|ttf|eot|svg|woff)$ {
##~*開頭表示不區(qū)分大小寫的正則匹配
root WeiXinVote;
}
##注意:前面必須加^~ ,提升配置的優(yōu)先級。
##^~ 開頭表示uri以某個常規(guī)字符串開頭弃鸦,理解為匹配 url路徑即可
location ^~ /upload/
{
proxy_pass http://tomcat_server/upload/;
proxy_set_header Host $host;
}
location /
{
proxy_pass http://tomcat_server/WeiXinVote/;
proxy_set_header Host $host;
}
}
關(guān)鍵代碼
location ~* \.(html|css|js|gif|jpg|jpeg|mp4|ttf|eot|svg|woff)$ {
##~*開頭表示不區(qū)分大小寫的正則匹配
root WeiXinVote;
}
# 也可以直接讀取磁盤绞吁,并指定緩存時間
location ~ ^/(js|css|plugins|img|json|font|html|gif|jpg|jpeg|png|bmp|swf)/ {
#所有靜態(tài)文件直接讀取硬盤
root D:/nginx-1.10.3/jd/;
expires 30d;
}