官方示例网站
开源地址:https://github.com/imsyy/DailyHot.git
# 前端镜像Dockerfile文件
FROM node:18-alpine as build-deps
WORKDIR /app
COPY . ./
RUN npm i -g pnpm
RUN pnpm install
RUN pnpm build
FROM nginx:1.12-alpine
# 环境变量
ENV VITE_GLOBAL_API "https://api-hot.efefee.cn"
ENV VITE_ICP "豫ICP备2022018134号-1"
# 拷贝静态文件
COPY --from=build-deps /app/dist /usr/share/nginx/html
COPY replace_apiurl.sh ./replace_apiurl.sh
RUN chmod +x replace_apiurl.sh
EXPOSE 80
CMD ["sh", "replace_apiurl.sh"]
# 脚本replace_apiurl.sh
#!/bin/bash
find '/usr/share/nginx/html' -name '*.js' -exec sed -i -e 's,vitegloalapi,'"$VITE_GLOBAL_API"',g' {} \;
find '/usr/share/nginx/html' -name '*.js' -exec sed -i -e 's,viteicp,'"$VITE_ICP"',g' {} \;
nginx -g "daemon off;"
# 修改.env文件
# 全局 API 地址
# VITE_GLOBAL_API="http://localhost:6688"
VITE_GLOBAL_API="https://api-hot.imsyy.top"
# ICP 备案号
VITE_ICP = "豫ICP备2022018134号-1"
# 全局目录
VITE_DIR = "/"
# 构建前端镜像
docker build -t [镜像地址]
一键部署
services:
dailyhotapi:
##image: dailyhot-api
image: docker.cnb.cool/srebro/pidin/dailyhotapi:latest ##CNB镜像加速地址
container_name: dailyhotapi
volumes:
- "./logs:/app/logs"
ports:
- 6688:6688
restart: always
dailyhotui:
image: docker.cnb.cool/srebro/pidin/dailyhotui:latest ##CNB镜像加速地址
container_name: dailyhotui
#environment:
# - VITE_GLOBAL_API=http://192.168.100.100:6688
ports:
- 8848:8848
restart: always
nginx反向代理
#dailyhotui
server {
listen 443 ssl;
server_name xxxxx;
error_page 404 /404/404.html;
charset utf-8;
ssl_certificate /home/application/nginx/cert/xxxx.pem;
ssl_certificate_key /home/application/nginx/cert/xxxx.key;
ssl_session_cache shared:SSL:1m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header x-wiz-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:8848;
}
location /api/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header x-wiz-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
##代理到DailyHotapi接口上
proxy_pass http://localhost:6688/;
}
}
搜集来自DailyHot | 一个聚合每日热门数据的 API 接口
cat docker-compose.yml
services:
dailyhot-api:
image: imsyy/dailyhot-api
container_name: dailyhot-api
restart: unless-stopped
ports:
- 6688:6688
dailyhot-web:
image: wbsu2003/dailyhot
container_name: dailyhot-web
restart: unless-stopped
ports:
- 6689:80
environment:
- VITE_GLOBAL_API=http://192.168.100.78:6688
- VITE_ICP=
# 访问地址
192.168.100.78:6689
参考资料: