Nginx本身也是一个静态资源的服务器,当只有静态资源的时候,就可以使用Nginx来做服务器,同时现在也很流行动静分离,就可以通过Nginx来实现,首先看看Nginx做静态资源服务器
动静分离是让动态网站里的动态网页根据一定规则把不变的资源和经常变的资源区分开来,动静资源做好了拆分以后,我们就可以根据静态资源的特点将其做缓存操作,这就是网站静态化处理的核心思路。
upstream test{?
???????server localhost:8080;?
???????server localhost:8081;?
????}?
????server {?
????????listen???????80;?
????????server_name? localhost;?
????????location / {?
????????????root?? e:/wwwroot;?
????????????index? index.html;?
????????}?
????????# 所有静态请求都由nginx处理,存放目录为html?
????????location ~ .(gif|jpg|jpeg|png|bmp|swf|css|js)$ {?
????????????root??? e:/wwwroot;?
????????}?
????????# 所有动态请求都转发给tomcat处理?
????????location ~ .(do)$ {?
????????????proxy_pass? http://test;?
????????}?
????????error_page???500?502?503?504??/50x.html;?
????????location = /50x.html {?
????????????root?? e:/wwwroot;?
????????}?
????}