配置-动静分离

四、 配置动静分离

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;

      ##设置欢迎页
           location = / {
            root  WeiXinVote;
            index index.html; 
       }
     location ~* \.(html|css|js|gif|jpg|jpeg|mp4|ttf|eot|svg|woff)$ {
         ##~*开头表示不区分大小写的正则匹配
           root  WeiXinVote;                
       }

        ##注意:前面必须加^~ ,提升配置的优先级。
        ##^~ 开头表示uri以某个常规字符串开头,理解为匹配 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;
          }
    }

关键代码

location ~* \.(html|css|js|gif|jpg|jpeg|mp4|ttf|eot|svg|woff)$ {
     ##~*开头表示不区分大小写的正则匹配
       root  WeiXinVote;                
   }
 # 也可以直接读取磁盘,并指定缓存时间
   location ~ ^/(js|css|plugins|img|json|font|html|gif|jpg|jpeg|png|bmp|swf)/ {
   #所有静态文件直接读取硬盘
    root D:/nginx-1.10.3/jd/;
   expires 30d;
   }

你可能感兴趣的:(配置-动静分离)