Ubuntu Docker 配置 Tomcat 和 Nginx 使用 HTTPS 访问
Ubuntu安装 Docker
使用脚本自动安装
curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh --mirror Aliyun
更改镜像地址
修改或新建 /etc/docker/daemon.json
{
"registry-mirrors": [
"https://registry.docker-cn.com"
]
}
启动 Docker
sudo systemctl daemon-reload
sudo systemctl enable docker
sudo systemctl start docker
--------------------------------------------------------------------------------
配置 Tomcat
启动 Tomcat 容器
docker pull tomcat
docker run --name tomcat -d -p 8080:8080 tomcat
修改 Tomcat Manager 应用
docker exec -it tomcat /bin/bash1
修改 webapps/manager/META-INF/content.xml,允许需要的IP访问,这里运行所有的IP访问
<Context antiResourceLocking="false" privileged="true" >
<Valve classname="org.apache.catalina.valves.RemoteAddrValve"
allow="^.*$" />
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
配置 Tomcat 用户
修改 conf/tomcat-user.xml,添加用户
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui,admin-gui"/>
--------------------------------------------------------------------------------
http://tomcat:8080: 将所有请求都转发到 tomcat 容器的 8080端口
启动 Nginx 容器
docker pull nginx
docker run --name nginx -d -p 80:80 -p 443:443 \
--link tomcat:tomcat \
-v /home/ubuntu/hellowood/dev/nginx/conf:/etc/nginx/conf.d \
-v /home/ubuntu/hellowood/dev/nginx/log:/var/log/nginx \
-v /home/ubuntu/hellowood/dev/nginx/certs:/etc/nginx/certs nginx