美文网首页
11,nginx动静分离

11,nginx动静分离

作者: 滔滔逐浪 | 来源:发表于2019-02-01 15:48 被阅读7次

    动静分离

    动静分离是让动态网站里的动态网页根据一定的规则把不变的资源好经常变的资源区分开来,动静资源做好了拆分以后,我们可以根据静态资源的特点将其做缓存操作,这就是网站静态处理的核心思路。

    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/;
    
    }
    
    20140614135657_TfSs2.thumb.700_0.jpeg

    相关文章

      网友评论

          本文标题:11,nginx动静分离

          本文链接:https://www.haomeiwen.com/subject/jvddsqtx.html