配置信息
1.域名DNS解析
由于本域名 https://www.dsxriiiii.cn 在阿里云购买 后服务器到期将DNS解析地址转移到京东云旗下
需要将解析文件导出到京东云
在阿里云修改解析地址 在京东云刷新 启动解析
2.配置nginx
首先安装docker
设置docker镜像源
yum-config-manager –add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新索引缓存列表
yum makecahe fast
安装docker-ce
yum install -y docker-ce
修改docker镜像拉取地址 修改配置文件
配置加速地址
配置加速地址:适用于Ubuntu 16.04+、Debian 8+、CentOS 7+
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://do.nark.eu.org",
"https://dc.j8.work",
"https://docker.m.daocloud.io",
"https://dockerproxy.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.nju.edu.cn"
]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
拉取nginx镜像
docker pull nginx
拷贝nginx配置文件
mkdir -p /tmp/nginx/conf
mkdir -p /tmp/nginx/log
mkdir -p /tmp/nginx/html
运行容器
docker run –name nginx -p 80:80 -d nginx
拷贝文件内容进行修改
docker cp nginx:/etc/nginx/nginx.conf /tmp/nginx/conf/nginx.conf
docker cp nginx:/etc/nginx/conf.d /tmp/nginx/conf.d
docker cp nginx:/usr/share/nginx/html /tmp/nginx/html
docker cp nginx:/usr/share/nginx/ssl /tmp/nginx/ssl
导入ssl证书
修改配置文件信息
主要修改内容为default.conf 文件内容如下
server {
listen 80;
listen [::]:80;
server_name dsxriiiii.cn;
rewrite ^(.*) https://$server_name$1 permanent;
}
server {
listen 443 ssl;
server_name dsxriiiii.cn;
ssl_certificate /etc/nginx/ssl/dsxriiiii.cn.pem;
ssl_certificate_key /etc/nginx/ssl/dsxriiiii.cn.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
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;
}
}
挂载文件到docker中
docker run \
-p 443:443 -p 80:80 \
--name nginx \
-v /tmp/nginx/conf/:/etc/nginx/conf/nginx.conf \
-v /tmp/nginx/log:/var/log/nginx \
-v /tmp/nginx/html:/usr/share/nginx/html \
-v /tmp/nginx/conf.d:/etc/nginx/conf.d \
-v /tmp/nginx/ssl:/etc/nginx/ssl \
-d nginx
访问结果
3.部署haper抽奖系统
1.使用maven打包项目
注意pom.xml文件中 运行的jar包中需要maven插件 否则无法运行java -jar命令
<dependencies>
...
</dependencies>
<build>
<finalName>Haper-app</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/**</include>
</includes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<skipTests>true</skipTests>
<testFailureIgnore>false</testFailureIgnore>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.6.0</version>
<configuration>
<mainClass>cn.dsxriiiii.Haper.Application</mainClass>
<layout>JAR</layout>
</configuration>
</plugin>
</plugins>
</build>
2.本地cmd测试运行jar包无误后上传到服务器
3.将jar包拷贝到/haper/haper-app/Haper-app.jar
4.编写DockerFile文件
FROM openjdk:8-jdk-alpine
EXPOSE 8091
WORKDIR /usr/data
COPY Haper-app.jar /usr/data/haper.jar
ENTRYPOINT ["java", "-jar", "/usr/data/haper.jar"]
5.构建镜像
docker build -t haper:1.0.0 .
注意小数点不要落下 并且当前执行命令的位置要在Dockerfile和jar包的所在位置
6.运行容器
docker run --restart=always -d -it --name=haper-app -p 8081:8081 -v /home/admin/app:/usr/data myapp:1.0.0
7.测试结果
远程调用接口无误 测试结果运行成功