properties 配置回车_在Ubuntu上部署基于Docker的RSSHub,并配置SSL证书
最近開始使用 RSS 這種信息聚合神器,再也不要打開各種 App 了。然而對于像微博、bilibili 這些不提供 RSS 訂閱的網站還是有些頭疼。于是嘗試了 RSSHub 這個東西,發現官方文檔中的示例服務在一些反爬很嚴格的網站上有時會失效,就考慮自己搭建一個。
一、安裝 Docker
1. 從官方 Docker 存儲庫安裝 Docker
參考?如何在 Ubuntu 上安裝使用 Docker - 云+社區 - 騰訊云 代碼如下:
$ sudo apt install apt-transport-https ca-certificates curl software-properties-common $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - $ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable" $ sudo apt update $ apt-cache policy docker-ce -y $ sudo apt install docker-ce -y查看Docker的運行狀態:
$ sudo systemctl status docker輸出應類似如下:
docker.service - Docker Application Container EngineLoaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)Active: active (running) since Thu 2018-07-05 15:08:39 UTC; 2min 55s agoDocs: https://docs.docker.comMain PID: 10096 (dockerd)Tasks: 16CGroup: /system.slice/docker.service├─10096 /usr/bin/dockerd -H fd://└─10113 docker-containerd --config /var/run/docker/containerd/containerd.toml二、部署 RSSHub
1. 安裝
參考?部署 | RSSHub 運行下面的命令下載 RSSHub 鏡像.
$ docker pull diygod/rsshub然后運行 RSSHub 即可
$ docker run -d --name rsshub -p 1200:1200 diygod/rsshub配置防火墻,開放1200端口,在瀏覽器中輸入「主機IP:端口號」,如果安裝成功,就會出現RSSHub歡迎界面。
可以使用下面的命令來關閉 RSSHub.
$ docker stop rsshub2. 更新
可以使用下面的命令來更新鏡像。
# 先關閉 rsshub $ docker stop rsshub# 刪除現有的容器 $ docker rm rsshub# 下載最新版的 rsshub 鏡像 $ docker pull diygod/rsshub3. 添加配置
配置運行在 docker 中的 RSSHub,最便利的方法是使用環境變量。
以設置緩存時間為 1 小時舉例,只需要在運行時增加參數:-e CACHE_EXPIRE=3600
# 此處添加自動重啟指令 $ docker run --restart=always -d --name rsshub -p 1200:1200 -e CACHE_EXPIRE=3600 -e GITHUB_ACCESS_TOKEN=example diygod/rsshub更多配置項請看 應用配置
三、設置 RSSHub 服務網址
該操作基于 nginx。通過設置子域名解析到部署 RSSHub 的服務器,以避免將服務器IP直接暴露出來。我們將基于 Let's Encrypt 配置 SSL 證書,讓 RSSHub 服務走 https,并且配置端口轉發,這樣 RSSHub 服務器地址就可以只用域名,而不需要加端口號。
1. 配置證書
在域名管理面板配置好子域名(下文使用 rss.example.com 作為示例),在服務器上配置證書。 參考 Nginx 實現 HTTPS(基于 Let's Encrypt 的免費證書) - kikajack的博客 - CSDN博客
1.1. 獲取官方工具 certbot-auto
$ wget https://dl.eff.org/certbot-auto # 下載到本地 $ chmod a+x ./certbot-auto # 添加可執行權限 $ ./certbot-auto --help all # 查看幫助1.2. 驗證域名所有權
配置 Nginx,使要獲取證書的域名對應的 80 端口可以正常訪問。在 /etc/nginx/conf.d/目錄下為域名創建新文件 rss.example.com.conf,并添加相關配置信息:
server {root /var/www/html;server_name rss.example.com;index index.html index.htm index.php;location ~ .php(.*)$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_split_path_info ^((?U).+.php)(/?.+)$;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param PATH_INFO $fastcgi_path_info;fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;include fastcgi_params;} }驗證配置文件是否有語法錯誤
$ sudo nginx -t如果沒有錯誤,輸出應類似如下:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful重啟 Nginx
$ sudo systemctl restart nginx 或 $ sudo nginx -s reload #有人說這個命令是否生效有些玄學,望大神解答1.3. 生成證書
$ sudo certbot-auto --nginx -d rss.example.com如果是第一次使用,會進入交互式界面,提示你輸入郵箱(在證書失效前收到通知郵件),并同意官方協議。證書生成成功后,會讓你選擇是否將所有的 HTTP 請求重定向到 HTTPS(輸入 1 或者 2)。 如果選 1,則通過 HTTP 和 HTTPS 都可以訪問。如果選 2,則所有通過 HTTP 來的請求,都會被 301 重定向到 HTTPS。本文選2,即全部重定向。 輸完 1 或者 2 回車后,會有成功提示,并說明證書放在 /etc/letsencrypt/live/證書的域名 這個位置:
IMPORTANT NOTES:- Congratulations! Your certificate and chain have been saved at:/etc/letsencrypt/live/rss.example.com/fullchain.pemYour key file has been saved at:/etc/letsencrypt/live/rss.example.com/privkey.pemYour cert will expire on 2019-03-09. To obtain a new or tweakedversion of this certificate in the future, simply run certbot againwith the "certonly" option. To non-interactively renew *all* ofyour certificates, run "certbot renew"- If you like Certbot, please consider supporting our work by:Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donateDonating to EFF: https://eff.org/donate-le2. 配置端口轉發
由于上文中使用 --nginx 參數,certbot-auto 會自動改寫配置文件,且所有改寫過的行都在后面加了注釋:# managed by Certbot。 我們在文件中添加如下配置:
location / {proxy_pass http://localhost:1200;proxy_set_header Host $host;proxy_redirect off;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;}驗證語法并重啟 nginx 后,訪問 https://rss.example.com/ 查看設置是否正確,如果設置正確,會看到歡迎界面。
四、信息安全
由于自建的 RSSHub 主要用來獲取自己感興趣的內容,而在其歡迎界面的 debug 項中,會輸出這些信息與請求者的 ip,因此在 nginx 中采取相關配置來阻止用戶訪問服務器根目錄。
官方實例中的 debug 項在端口轉發配置上方添加如下配置:
location = / {return 404; }這樣,當用戶訪問 https://rss.example.com/ 時,會返回錯誤 404,從而達到阻止用戶訪問歡迎界面的目的。
參考匯總
總結
以上是生活随笔為你收集整理的properties 配置回车_在Ubuntu上部署基于Docker的RSSHub,并配置SSL证书的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 余弦函数导数推导过程_人工智能数学基础-
- 下一篇: java赋值语句_Scala守卫语句的集