#将Nginx
容器当中的配置拷贝到本地修改,因为容器当中没有vi vim命令
[root@localhost ~]# docker cp 68d2bdf336ed:/etc/nginx/conf.d/default.conf .
[root@localhost ~]# ls
anaconda-ks.cfg default.conf index.html
[root@localhost ~]# grep -vE “#|^$” default.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
#两台tomcat的ip地址
[root@localhost ~]# for i in {72e174adc77d,080068dae40a};do docker inspect $i| grep -i ipaddr |tail -n 1;done
“IPAddress”: “172.17.0.4”,
“IPAddress”: “172.17.0.3”,
拷贝静态资源到Nginx目录下做
动静分离 ,同时修改配置文件
#将其中一台Tomcat的ROOT目录拷贝到本地,因为做动静分离Nginx需要访问静态资源要在本地
[root@localhost ~]# docker cp 72e174adc77d:/usr/local/tomcat/webapps/ROOT .
#拷贝到Nginx发布目录下面
[root@localhost ~]# docker cp ROOT 68d2bdf336ed:/usr/share/nginx/html/
[root@localhost WEB-INF]# docker exec 68d2bdf336ed ls -l /usr/share/nginx/html/ROOT
total 184
-rwxrwxrwx 1 root root 7064 Jun 21 2017 RELEASE-NOTES.txt
drwxrwxrwx 2 root root 21 Jul 27 2017 WEB-INF
-rwxrwxrwx 1 root root 26447 Jun 21 2017 asf-logo-wide.svg
-rwxrwxrwx 1 root root 713 Jun 21 2017 bg-button.png
-rwxrwxrwx 1 root root 1918 Jun 21 2017 bg-middle.png
-rwxrwxrwx 1 root root 1392 Jun 21 2017 bg-nav-item.png
-rwxrwxrwx 1 root root 1401 Jun 21 2017 bg-nav.png
-rwxrwxrwx 1 root root 3103 Jun 21 2017 bg-upper.png
-rwxrwxrwx 1 root root 21630 Jun 21 2017 favicon.ico
-rwxrwxrwx 1 root root 12279 Jun 21 2017 index.jsp
-rwxrwxrwx 1 root root 2376 Jun 21 2017 tomcat-power.gif
-rwxrwxrwx 1 root root 5581 Jun 21 2017 tomcat.css
-rwxrwxrwx 1 root root 2066 Jun 21 2017 tomcat.gif
-rwxrwxrwx 1 root root 5103 Jun 21 2017 tomcat.png
-rwxrwxrwx 1 root root 67795 Jun 21 2017 tomcat.svg
#修改后的Nginx配置文件如下,修改完后拷贝会容器当中
[root@localhost ~]# docker cp default.conf 68d2bdf336ed:/etc/nginx/conf.d/default.conf
[root@localhost ~]# docker exec 68d2bdf336ed cat /etc/nginx/conf.d/default.conf
upstream tomcat_web{
server 172.17.0.3:8080 weight=100 max_fails=2 fail_timeout=15;
server 172.17.0.4:8080 weight=100 max_fails=2 fail_timeout=15;
}
server {
listen 80;
listen [::]:80;
server_name localhost;
error_page 500 502 503 504 /50x.html;
root /usr/share/nginx/html;
location /{
proxy_pass http://tomcat_web;
proxy_set_header host $host;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
root /usr/share/nginx/html/ROOT;
expires 30d;
access_log off;
}
location ~ .*\.(eot|ttf|otf|woff|svg)$ {
root /usr/share/nginx/html/ROOT;
expires 30d;
access_log off;
}
location ~ .*\.(js|css)$ {
root /usr/share/nginx/html/ROOT;
expires 30d;
access_log off;
}
location = /50x.html {
root /usr/share/nginx/html;
}
}
#加载新的配置项
[root@localhost ~]# docker exec -it 68d2bdf336ed /bin/bash
root@68d2bdf336ed:/# /usr/sbin/nginx -s reload
2020/06/29 07:12:05 [notice] 79#79: signal process started