11,nginx動靜分離

weixin_34107955發表於2019-02-01

動靜分離

動靜分離是讓動態網站裡的動態網頁根據一定的規則把不變的資源好經常變的資源區分開來,動靜資源做好了拆分以後,我們可以根據靜態資源的特點將其做快取操作,這就是網站靜態處理的核心思路。

server{
   listen 80;
   server_name   mmm.com; #(在host裡配置:   127.0.0.1  mmm.com),或者直接localhost替換mmm.com
   rewrite_log    on;
        
     location /game/api/{      #動態的api介面  
       proxy_pass  http://127.0.0.1:8080/api/;    #api介面的字首,如  /api/index   
#     訪問介面:  http://mmm.com/game/api/index   就訪問到了index的介面
    #Proxy Settings
           proxy_redirect     off;
           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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
           proxy_max_temp_file_size 0;
           proxy_connect_timeout      90;
           proxy_send_timeout         90;
  proxy_read_timeout         90;
           proxy_buffer_size          4k;
           proxy_buffers              4 32k;
           proxy_busy_buffers_size    64k;
           proxy_temp_file_write_size 64k;
}  



location  /game/index.html {  #訪問的靜態頁面index    
      alias D:/works/myfile/springboot/1225/jsp/src/main/resources/templates/index.html;  #頁面的路徑

}

location  /game/image/{   #訪問圖片   http://mmm.com/game/image/2.png
   alias D:/works/myfile/springboot/1225/jsp/src\main/resources/static/imag/temp/;  #圖片路徑

}


location  /game/templates {    #訪問templates下的的靜態頁面  http://mmm.com/game/templates/index.html
      alias D:/works/myfile/springboot/1225/jsp/src/main/resources/templates/;

}
12197462-d25235245699a8ab.jpeg
20140614135657_TfSs2.thumb.700_0.jpeg

相關文章