修改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;
} }