使用 DigitalOcean 建立一個 Ubunutu14.04 的機器
建立使用者 adduser
新建立的機器只有 root 先建立一位使用者
adduser ming
將剛建立的使用者 加入 sudoer
export EDITOR=vim
visudo
安裝 zsh, git
sudo apt-get install zsh
sudo apt-get install git
chsh -s /bin/zsh
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
Step1 apache server
安裝 apache server
sudo apt-get update
sudo apt-get install apache2
假設 DigitalOcean 為該機器分配的 IP 為 45.55.15.52
打開瀏覽器 輸入
45.55.15.52
或是
http://45.55.15.52
在安裝好之後 檢查 server 有無正常啟動
netstat -an|grep 80
Step2 申請 dns
在 freedns 註冊一個帳號 可免費申請
http://freedns.afraid.org/domain/registry/
將 DigitalOcean 為該機器分配的 IP 為 45.55.15.52 與喜歡的名字綁定
例如: helloworld.port0.org
設定好之後 檢查該綁定是否生效
nslookup helloworld.port0.org
apache enable ssl
接著設定 啟用 ssl
sudo ln -s ../sites-available/default-ssl.conf 001-ssl.conf
cd /etc/apache2/sites-enabled
sudo vim 001-ssl.conf # 修改檔案開頭的部分 加入一行
新增一行
ServerName helloworld.port0.org
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
ServerName helloworld.port0.org
DocumentRoot /var/www/html
在安裝 apache ssl 模組並重新啟動 apache server
sudo a2enmod ssl
sudo service apache2 restart
此時 應該能夠順利訪問
或是
netstat -an|grep 443
Step3 自動申請 Let's Encrypt ssl 憑證
https://github.com/certbot/certbot
cd ~
wget https://dl.eff.org/certbot-auto
chmod a+x ./certbot-auto
./certbot-auto
選擇 Easy configuration
certbot-auto 會自動讀取 apache 相關的設定並進行適當的修改
shellbox
https://github.com/shellinabox/shellinabox
sudo apt-get install shellinabox
檢查服務是否有啟動
netstat -an|grep 4200
ps aux | grep shell
shellinabox apache2 設定
cd /etc/apache2
sudo vim sites-available/default-ssl.conf
在檔案結尾處新增三行
<Location /shell>
ProxyPass http://localhost:4200/
</Location>
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
SSLCertificateChainFile /etc/letsencrypt/live/pypyso.port0.org/chain.pem
</VirtualHost>
<Location /shell>
ProxyPass http://localhost:4200/
</Location>
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
由於使用了 ProxyPass 需要啟用 proxy_http 並重啟 apache server
sudo a2enmod proxy_http
sudo service apache2 restart
訪問
https://helloworld.port0.org/shell
就可以順利透過 瀏覽器 登入機器
Reference
https://help.ubuntu.com/community/shellinabox
https://help.ubuntu.com/community/shellinabox
Enable SSL for apache server in 5 minutes
https://hallard.me/enable-ssl-for-apache-server-in-5-minutes/
Too many certificates already issued https://community.letsencrypt.org/t/too-many-certificates-already-issued/6481