问题
如果在ctfd_ctfd_1容器的前一面套一层nginx,然后使用nginx反向代理指向容器,可能会导致ctfd获取用户IP错误的情况
如下图中的172.1.0.10就是nginx容器的ip
解决方案
在ctfd中,目录CTFd/CTFd/config.ini中,有个配置修改一下,将REVERSE_PROXY设置为true即可
附上nginx.conf,如果有需要的小伙伴可以参考:
events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;client_max_body_size 50m;set_real_ip_from 0.0.0.0/0;real_ip_header X-Forwarded-For;server{listen 80;server_name domain.com;location / {proxy_pass http://172.1.0.5:8000/; #此处填写你ctfd_ctfd_1容器IPproxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-Proto https;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_connect_timeout 150;proxy_send_timeout 100;proxy_read_timeout 100;proxy_buffers 4 32k;client_max_body_size 8m;client_body_buffer_size 128;}}}
后记
目前还没找到能实现在cloudflare代理流量+nginx反代获取用户真实IP的方案,如果使用nginx反代+cloudflare代理,ctfd后端获取的IP为cloudflare泛播地址,如下:
如果有大佬有相应的解决方案,俺给你磕头,教教我~
