我的问题是通过ssl从nginx级别的网络上获取静态vuejs站点的“真实”IP地址。
我想阻止某些IP地址,如果我不能使用代理传递,我如何才能获得真实的IP地址,因为我只链接到静态位置?
haproxy (tcp) (端口: 443) ==> encrypted request ==> 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 4snginx设置:
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;
}
}发布于 2019-11-28 04:02:58
在nginx端,您可以使用服务器块的deny all和allow范围来控制允许哪些IP地址或范围,如下所示:
allow 192.168.1.0/24;
deny all;注意: nginx文档总是一个很好的起点,这里是restricting access by IP addresses和ranges的文档。
首先,我要挑战你重新思考为什么你需要一个带有haproxy的负载均衡器来处理像html/css/js这样简单的静态站点。更多的基础设施会带来更多的复杂性。
其次,nginx中的上游只在你想将请求指向本地wsgi服务器时才需要,例如,在你的例子中,这是静态内容,所以你不需要指向上游-除非你有某种类型的wsgi服务你想转发请求。
最后,对于haproxy只转发127.0.0.1的请求,首先确保IP在报头中(即X-Real-IP),然后您可以尝试在haproxy配置(source)中添加类似以下内容,如果您确实想保留haproxy:
frontend all_https
option forwardfor header X-Real-IP
http-request set-header X-Real-IP %[src]haproxy文档也是一个很好的preserving source IP addresses资源。
https://stackoverflow.com/questions/59073187
复制相似问题