安装 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/bash
<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 用户
<@H_403_97@role rolename="admin-gui"/>
<@H_403_97@role rolename="manager-gui"/>
<@H_403_97@user username="tomcat" password="tomcat" roles="manager-gui,admin-gui"/>
配置 Nginx
配置目录
- 新建目录
/home/ubuntu/hellowood/dev/Nginx/conf
,/home/ubuntu/hellowood/dev/Nginx/log
,/home/ubuntu/hellowood/dev/Nginx/certs
- 下载并解压相应的Nginx证书文件到
/home/ubuntu/hellowood/dev/Nginx/conf
添加 Nginx 配置
- Nginx.conf
server {
listen 80;
listen 443 ssl;
server_name hellowood.com.cn;
ssl_certificate /etc/Nginx/certs/hellowood.com.cn_bundle.crt;
ssl_certificate_key /etc/Nginx/certs/hellowood.com.cn.key;
location / {
proxy_pass http://tomcat:8080;
}
}
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
此时,访问相应的域名:http://hellowood.com.cn
和https://hellowood.com.cn
会显示Tomcat
的首页,配置完成