1.动静分离
———————————————————————————————————————————————————-
1)动态资源:
location ~ .*.(jsp|do|action)$ {
proxy_pass http://tomcat-01:8080;
}
(其中~代表大小写敏感,第一个点为 匹配任何的非回车字符,*为多个或者零个,$代表结尾,均为正则表达式表示符号)
———————————————————————————————————————————————————-
2)静态资源:
location ~ .*.(html|js|css|gif|jpg|jpeg|png)$ {
expires 3d;(控制图片等过期时间为3天)
}
———————————————————————————————————————————————————-
2.负载均衡
http {
upstream tomcats {
server tomcat-01:8080 weight=1;
server tomcat-02:8080 weight=1;
server tomcat-03:8080 weight=1;
}
———————————————————————————————————————————————————-
location ~ .*.(jsp|do|action) {
proxy_pass http://tomcats;
(这个在server里配置)
———————————————————————————————————————————————————-
本文详细介绍了Nginx中动静分离及负载均衡的配置方法。动静分离方面,通过正则匹配实现了动态资源(如JSP页面)和静态资源(如HTML、JS文件)的有效分离;负载均衡部分,则通过配置upstream定义了多个Tomcat服务器,并设置权重进行任务分配。
572

被折叠的 条评论
为什么被折叠?



