前言:
x上的一个帖子,看着APP不错。 GitHub 接在图片下。
GitHub: GitHub - ourongxing/newsnow: Elegant reading of real-time and hottest news
增加 SSL 功能与更换端口号为9015
1. 使用 Nginx 来作为反向代理来处理 SSL
- a. 使用之前文章创建的 cert.pem key.pem 证书文件
- b. 创建 nginx.conf 配置文件,内容如下:
events {
worker_connections 1024;
}
http {
upstream newsnow {
server newsnow:9015;
}
server {
listen 9015 ssl;
ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/key.pem;
location / {
proxy_pass http://newsnow;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
2. 在 docker-compose.yml 添加 Nginx 服务, 修改内/外端口号
文件如下:
version: '3'
services:
newsnow:
image: ghcr.io/ourongxing/newsnow:latest
container_name: newsnow
restart: always
environment:
- PORT=9015
- G_CLIENT_ID=
- G_CLIENT_SECRET=
- JWT_SECRET=
- INIT_TABLE=true
- ENABLE_CACHE=true
nginx:
image: nginx:alpine
ports:
- "9015:9015"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./ssl:/etc/nginx/ssl:ro
depends_on:
- newsnow
3. 创建证书文件目录
app 的目录下文件比较多, 为了清楚, 证书文件放到 ./ssl 目录,见 docker-compose.yml 倒数第三行。
[/share/Multimedia/2024-MyProgramFiles/30.GitHub_Apps/1.newsnow-0.0.20] # mkdir -p ssl
把证书文件到放到:./ssl 目录里面
Docker 中部署
在 docker-compose.yml 目录下运行命令: docker compose up -d
[/share/Multimedia/2024-MyProgramFiles/30.GitHub_Apps/1.newsnow-0.0.20] # docker compose up -d
WARN[0000] /share/Multimedia/2024-MyProgramFiles/30.GitHub_Apps/1.newsnow-0.0.20/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion
[+] Running 9/9
✔ nginx Pulled 7.9s
✔ da9db072f522 Pull complete 2.0s
✔ e10e486de1ab Pull complete 2.7s
✔ af9c0e53c5a4 Pull complete 2.8s
✔ b2eb2b8af93a Pull complete 2.9s
✔ e351ee5ec3d4 Pull complete 3.1s
✔ fbbf7d28be71 Pull complete 3.2s
✔ 471412c08d15 Pull complete 3.3s
✔ a2eb5282fbec Pull complete 6.3s
[+] Running 3/3
✔ Network 1newsnow-0020_default Created 2.5s
✔ Container newsnow Started 1.9s
✔ Container 1newsnow-0020-nginx-1 Started 3.5s
[/share/Multimedia/2024-MyProgramFiles/30.GitHub_Apps/1.newsnow-0.0.20] #
界面
结束语:
如有些内容没有获取,问墙。