2023年8月10日 星期四

HAProxy Reverse Proxy with SSL

憑證掛在 Reverse Proxy, 內部走 HTTP

frontend http-in
mode http
bind *:80
bind *:443 ssl crt /etc/haproxy/pank.org-crt-chain-key.pem
use_backend %[req.hdr(Host),lower]

backend test1.pank.org
balance first
mode http
option forwardfor except 127.0.0.0/8
server web-1 192.168.0.27:80

backend test2.pank.org
balance first
mode http
option forwardfor except 127.0.0.0/8
server web-2 192.168.0.42:80

test1.pank.org 及 test2.pank.org 使用同一個 wildcard 憑證,
crt 是 crt+chain+key 放同一個檔
若兩個站的憑證不同,可以用 crt-list 指定多個憑證
例: bind *:443 ssl crt-list /etc/haproxy/crt-list.txt
crt-list.txt 的內容
/etc/haproxy/domain1.com-crt-chain-key.pem
/etc/haproxy/domain2.com-crt-chain-key.pem
有設定 option forwardfor 會帶 X-Forwarded-For 到 backend server

2023年8月9日 星期三

NGINX Reverse Proxy with SSL

憑證掛在 Reverse Proxy, 內部走 HTTP

/etc/nginx/conf.d/test1.conf

server {
listen 443 ssl;
server_name test1.pank.org;
ssl_certificate /etc/nginx/conf.d/pank.org-crt-chain.pem;
ssl_certificate_key /etc/nginx/conf.d/pank.org-key.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
add_header X-Proxy-Cache $upstream_cache_status;
proxy_pass http://192.168.0.27;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

若後端有多台,建立多個 conf 即可
有設定 proxy_set_header X-Forwarded-For 會帶 X-Forwarded-For 到 backend server

Apache Reverse Proxy with SSL

憑證掛在 Reverse Proxy, 內部走 HTTP

<VirtualHost *:443>
ServerName test1.pank.org
ServerAdmin pank@pank.org
ErrorLog "/var/log/httpd/test1_error_log"
TransferLog "/var/log/httpd/test1_access_log"
SSLEngine on
ProxyPass / http://192.168.0.27/
ProxyPassReverse / http://192.168.0.27/
SSLProtocol all -SSLv2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLCertificateFile "/etc/httpd/conf.d/pank.org-crt.pem"
SSLCertificateKeyFile "/etc/httpd/conf.d/pank.org-key.pem"
SSLCertificateChainFile /etc/httpd/conf.d/chain.pem
</VirtualHost>

若後端有多台,建立多個 VirtualHost 區塊即可
Apache 預設就會帶 X-Forwarded-For 到 backend server,不用特別設定

2023年8月3日 星期四

yt-dlp - youtube-dl replacement

youtube-dl 之前是一個好用的視頻下載工具,但在 2020 年 10 月,被 RIAA 要求下架,
Github 也關閉了它及其他 fork 的專案
但在很多使用者抱怨下,2020 年 11 月 Github 恢復了 youtube-dl 的專案,
但是近來都沒更新了,最後更新日期是 2021 年 12 月
yt-dlp 是 youtube-dl 的 fork,仍常常更新,可視為 youtube-dl 的替代品

Stunnel

Stunnel 有點像 SSH tunnel,可以建立加密通道 原本未加密的協議,讓它走 Stunnel,就可以達到不改變協議,數據有加密的效果 以下用一個實例說明: A 要 telnet B,IP 12.34.56.78,因 telnet 協議本身未加密, 若要讓 A 到 B...