Posts

Showing posts with the label SSL

使用 acme.sh 搭配 Let's encrypt 申請 wildcard ssl 憑證

Image
之前一直都是使用 certbot 套件 不過換到 CentOS 8 後 這個套件到今天(2020.05.28)為止還沒支援就是 由於 certbot 是用 pythlon 開發的 所以安裝時會安裝一堆相依的套件 這也是我一直不喜歡用 certbot 的原因 會間接搞亂我的環境 後來找到 acme.sh 是使用 shell script 撰寫的 相對來說單純很多 安裝也很簡單 這個範例是搭配 Cloudflare DNS 做設定 安裝 acme.sh 我是使用 root 執行安裝的 curl  https://get.acme.sh | sh 所以安裝完會出現 /root/.acme.sh 這個資料夾 取得 Cloudflare 的 key 登入你的 cloudflare 帳號後 到這個頁面  https://dash.cloudflare.com/profile/api-tokens 點選下方「Global API Key」右邊的 View 認證完後會取得一組 Key 申請 SSL 憑證 在 /root/ 下新增一個 ssl_cert.sh 檔案 其中 yourdomain.tld 為你自己的網域名稱,如 google.com 因為有指定目錄於 /etc/letsencrypt 中 所以憑證應該會出現在 /etc/letsencrypt/yourdomain.tld 下 由於是 wildcard 的關係,所以會指定兩個 domain 分別為 yourdomian.tld 及 *.yourdomain.tld 請注意,務必讓 yourdomain.tld 在第一個,如果讓 *.yourdomain.tld 在前面的話,你的資料夾就會是 *.yourdomain.tld export CF_Key="your global api key" export CF_Email="你的 cloudflare 登入的帳號(信箱)" /root/.acme.sh/acme.sh --issue -d yourdomain.tld -d *.yourdomain.tld --cert-home /etc/letsencrypt --keylength 2048 --dns dns_cf \ --reloadcmd "system...

Apache run multiple SSL Virtual Host

基本上要 run single SSL site 在 Apache 上還蠻容易的 但再加上了一個 SSL site 問題就來了 不就在 SSL zone (httpd-ssl.conf)那邊加上另外一個 Virtual Host 就好了嗎? SSL 的 Virtual Host 從 Name Based 換到 IP Based 再加上額外的 Private IP 也是不行 後來用瀏覽器連 Private IP 的 SSL 卻是正常的 才想到說應該把那 Private IP 也 mapping 到另外一個 Public IP 由於我們公司主機在防火牆下 所以除了更改 DNS 外,還有修改一下防火牆的規則 舉個實際例子說明: Public IP 200.200.200.1 (80 & 443) 原本對應到 Private IP 10.1.1.1 後來加入了一個 10.1.1.2 的 Private IP 但連 https://b.test.com 他顯示的認證還是 b.test.com 的 如果只有一個 Public IP 那就只能指定其他的 port(如 https://200.200.200.1:4433) 了 80 跟 443 以外的 port 一般人都蠻難接受的(要公開的話很不方便,自用就還好) 所以還是多個 IP 好辦事阿~ 提供 Apache 的相關設定供參考 這邊僅提供 SSL Virtual Host 的部份 我並沒有去設別設定 Port 80 (httpd-vhost.conf)那邊 Port 80 (httpd-vhost.conf)那邊還是維持 Name Based 的方式 Listen 10.1.1.1:443 Listen 10.1.1.2:443 NameVirtualHost 10.1.1.1:443 NameVirtualHost 10.1.1.2:443   DocumentRoot "/home/www/a.test.com"   ServerName a.test.com:443   ServerAdmin service@test.com   ErrorLog "/usr/local/apache2/logs/error...