這是本文件的舊版!
網站取得用戶真實 IP 的方法
- 目前網站的網路架構愈來愈複雜, 要取得用戶真實的 IP 需要透過特別指定與層層的傳遞才有機會取得, 以下透過一個實驗環境的架構案例進行說明
- Client (1.2.3.4) –(HTTPS)→ Cloudflare CDN –(Encrypted Tunnel)–> Host A (192.168.1.1) - Cloudflared –(HTTP LAN)–> Host B (192.168.1.100:80) - NginxProxyManager –(HTTP Overlay Network)–> Backend Service (http://dokuwiki_dokuwiki:80)
graph LR
subgraph 部署環境
subgraph Docker Swarm (192.168.1.0/24)
subgraph Host B (192.168.1.100)
B[NginxProxyManager:80]
style B fill:#f9f,stroke:#333
end
subgraph Overlay Network
D[(dokuwiki_dokuwiki:80)]
style D fill:#ddf,stroke:#333
end
B -- HTTP Overlay Network --> D
end
end
A[Client (1.2.3.4)]
C<a href='/_media/tech/cloudflare_cdn' class='media mediafile mf_ wikilink2' title='tech:cloudflare_cdn'>cloudflare_cdn</a>
E[Host A (192.168.1.1) - Cloudflared]
A -- HTTPS --> C
C -- Encrypted Tunnel --> E
E -- HTTP LAN --> B
style A fill:#ccf,stroke:#333
style C fill:#afa,stroke:#333
style E fill:#fcc,stroke:#333
%% 標籤解釋
classDef client fill:#ccf,stroke:#333
classDef cdn fill:#afa,stroke:#333
classDef tunnel fill:#fcc,stroke:#333
classDef proxy fill:#f9f,stroke:#333
classDef backend fill:#ddf,stroke:#333