[英]nginx behind haproxy to static html ssl getting real IP address
我的問題是從 nginx 級別的網絡獲取“真實”IP 地址,通過 ssl 為靜態 vuejs 站點提供服務。
我想屏蔽某些IP地址,如果我不能使用代理通行證,我如何獲得真實的IP地址,因為我只鏈接到一個靜態位置?
haproxy (tcp) (端口: 443) ==> 加密請求 ==> nginx (端口: 8085) 請求傳遞到 ==> '/' 位置獲取用於范圍阻塞的真實 IP。
另請參閱 nginx vhost 文件中的問題/評論。 我在這里是在正確的軌道上還是需要以完全不同的方式完成?
haproxy 設置:
frontend ssl_front_433 xx.xx.xx.xx:443
mode tcp
option tcplog
use_backend ssl_nginx_backend_8085
backend ssl_nginx_backend_8085
mode tcp
balance roundrobin
option tcp-check
server srv-2 127.0.0.1:8085 check fall 3 rise 2 inter 4s
nginx設置:
server {
listen 8085 ssl;
server_name mydomain;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
ssl_certificate ./fullchain.pem;
ssl_certificate_key ./privkey.pem;
include include.d/ssl.conf;
// I want to only allow certain ip addresses
// haproxy of course always returns 127.0.0.1 thus this is not working
include include.d/ip_range.conf;
location / {
//how to get the proxy headers to be applied here?
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
// do I need a proxy pass and if so where should I pass to,
// in order to use it with static html/js?
// can I use an upstream to a static location?
//proxy_pass http://;
try_files $uri $uri/ /index.html;
}
}
在 nginx 方面,您可以使用deny all
和allow
范圍來控制允許哪些 IP 地址或范圍到您的服務器塊,如下所示:
allow 192.168.1.0/24;
deny all;
注意:nginx 文檔始終是一個很好的起點,這里是通過 IP 地址和范圍限制訪問的文檔。
首先,我會挑戰你重新考慮為什么你需要一個帶有 haproxy 的負載均衡器來處理像 html/css/js 靜態站點這樣簡單的事情。 更多的基礎設施引入了更多的復雜性。
其次,僅當您想將請求指向本地 wsgi 服務器時才需要 nginx 中的上游,例如,在您的情況下,這是靜態內容,因此您不需要指向上游 - 除非您有某種 wsgi要將請求轉發到的服務。
最后,對於 haproxy 僅將請求轉發為 127.0.0.1,首先確保 IP 位於標頭中(即X-Real-IP
),然后您可以嘗試將類似的內容添加到您的 haproxy 配置( 源)中,如果您確實如此想要保持haproxy:
frontend all_https
option forwardfor header X-Real-IP
http-request set-header X-Real-IP %[src]
haproxy 文檔也是保存源 IP 地址的好資源。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.