1)先搞一个静态资源服务器
copy宿主机nginx共享目录一份:nginx2
hosts:192.168.147.156 static.feidao.com
docker run -it -p 1010:1010 --name=staticNginx -v /home/data/nginx2:/etc/nginx -v /home/data/nginx2data:/home/nginx 镜像ID
修改nginx2中nginx.conf与default.conf文件
nginx.conf中不要配置upstream,因为nginx2只是用作静态资源服务器用,并非是代理服务器
default.conf配置如下:
listen 1010;
server_name static.feidao.com;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /home/nginx;
#proxy_pass http://172.17.0.3:8080;
#proxy_pass http://www.feidao.com;
index index.html index.htm;
}
输入: http://static.feidao.com:1010/
出现下图:就算静态资源服务器搞出来了
nginx.conf配置如下:
#gzip on;
upstream www.feidao.com{
server 172.17.0.3:8080 weight=1;
server 172.17.0.2:9090 weight=2;
}
upstream static.feidao.com{
server 172.17.0.5:1010;
}
include /etc/nginx/conf.d/*.conf;
default.conf配置如下:
listen 80;
server_name www.feidao.com;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
#root /usr/share/nginx/html;
#proxy_pass http://172.17.0.3:8080;
proxy_pass http://www.feidao.com;
index index.html index.htm;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
proxy_pass http://static.feidao.com;
}
location ~ .*\.(js|css)?$ {
proxy_pass http://static.feidao.com;
}
location ~ .*\.(html)?$ {
proxy_pass http://static.feidao.com;
}
3)修改tomcat1、tomcat2中的index.jsp,方便myNginx代理服务器的代理效果
tomcat1中的index.jsp修改如下
tomcat2依葫芦画瓢,这里就不截图了;
4)最终动静分离效果
出现下图算是动静分离成功
over......
备案号:湘ICP备19000029号
Copyright © 2018-2019 javaxl晓码阁 版权所有