nginx靜態資源分離部署


修改nginx.conf文件,用於nginx處理靜態資源。

 

主要配置如下(在server配置中加入location配置即可):


server { listen 80; server_name 123.57.162.75; charset utf-8; index index.html index.htm index.jsp index.do; root /opt/nginx-1.4.7/html/resources; #配置Nginx動靜分離,定義的靜態頁面直接從Nginx發布目錄讀取。 location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ { root /opt/nginx-1.4.7/html/resources; #expires定義用戶瀏覽器緩存的時間為7天,如果靜態頁面不常更新,可以設置更長,這樣可以節省帶寬和緩解服務器的壓力 expires 7d; } }

upstream blog.ha97.com {
 
#upstream的負載均衡,weight是權重,可以根據機器配置定義權重。weigth參數表示權值,權值越

高被分配到的幾率越大。
 
server 192.168.80.121:80 weight=3;
 
server 192.168.80.122:80 weight=2;
 
server 192.168.80.123:80 weight=3;
 
}

 

#本地動靜分離反向代理配置
 
#所有jsp的頁面均交由tomcat或resin處理
 
location ~ .(jsp|jspx|do)?$ {
 
proxy_set_header Host $host;
 
proxy_set_header X-Real-IP $remote_addr;
 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 
proxy_pass http://127.0.0.1:8080;
 
}
 
#所有靜態文件由nginx直接讀取不經過tomcat或resin
 
location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|

pdf|xls|mp3|wma)$
 
{ expires 15d; }
 
location ~ .*.(js|css)?$
 
{ expires 1h; }
 
}
 
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM