欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

nginx动静分离

程序员文章站 2022-05-31 12:23:23
...

动静分离

      Nginx负责处理客户端的静态文件的处理,让Tomcat专心处理动态的请求。主要配置看高亮处:

 

案例

server {

listen       80;

server_name  127.0.0.1;

index index.shtml

 

charset utf-8;

 

#access_log  logs/host.access.log  main;

 

location /module1 {

proxy_pass http://127.0.0.1:8080;

}

 

location /module1 {

proxy_pass http://127.0.0.1:8081;

}

 

location /module3 {

proxy_pass http://127.0.0.1:8082;

}  

 

location /module4 {

proxy_pass http://127.0.0.1:8083;

}

 

location ~ ^/main/.*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {

root /opt/package/tomcat7/eam-tomcat/webapps/;

expires      3d;

}

 

location ~ ^/module1/.*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {

root /opt/package/tomcat7/bl-tomcat/webapps/;

expires      3d;

}  

 

location ~ ^/module3/.*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {

root /opt/package/tomcat7/cd-tomcat/webapps/;

expires      3d;

 

location ~ ^/module3/.*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {

root /opt/package/tomcat7/df-tomcat/webapps/;

expires      3d;

}  

}