yo @Falco, nginx 로그에 real_ip(cf가 CF-Connecting-IP 헤더로 제공하는)가 제대로 들어오고 있나요? 제 경우에는 안 들어오네요. cloudflared의 IP만 보입니다.
아래 중 하나 또는 둘 다 처리가 필요할 것 같습니다(조사 후 후속 조치하겠습니다):
cloudflared의 IP에 대해 nginx 설정에 set_real_ip_from 설정 라인을 추가해야 합니다. 만약 이것이 문제라면, templates/cloudflare.template.yml에서 제공하는 다른 set_real_ip_from 라인들은 argotunnel 사용자에게 필요하지 않을 것으로 추측됩니다. 이 경우, 메인 app.yml에서 cloudflared IP를 환경 변수 등으로 가져오는 별도의 argotunnel 템플릿을 docker 저장소에 추가하는 것이 좋을 수 있습니다.
log_format 수정. 이 부분은 아마도 문제가 아닐 것 같습니다. 필요 없음 확인
수정:
제가 동작하게 만드는 방법입니다:
cloudflare 템플릿을 사용하지 마세요. 의미가 없습니다.
대신, 다음 내용을 app.yml에 병합하세요:
hooks:
after_web_config:
- file:
path: /etc/nginx/conf.d/cloudflare_tunnel_real_ip.conf
contents: |
# restore original visitor IPs (ngx_http_realip_module)
set_real_ip_from 10.100.20.200/32; # your cloudflared/argotunnel IP range
real_ip_header CF-Connecting-IP;
참고로, 이 설정은 자동으로 nginx의 http 컨텍스트에 들어가는데, 이것이 적절한 위치입니다.
P.S. 제 생각에는 깔끔함을 위해 cloudflare 템플릿도 nginx 설정을 sed -i를 사용해 /etc/nginx/conf.d/discourse.conf에 추가하는 대신 별도의 파일로 생성해야 합니다.
네 @shyguy, @Falco 님의 단계를 따르고 있습니다.
네, 터널을 사용하고 있습니다. Cloudflare에서 DDoS 보호를 받기 전에는 DDoS 공격으로 인해 서버 CPU 사용률이 매우 높았고, 액세스 로그가 20MB까지 차올랐으며, 로그에는 제 도커 IP만 확인되었습니다. 서버를 보호하기 위해 / URL 경로에 방문자를 대상으로 챌린지를 설정했는데, 만료된 캐시 때문에 Discourse에서 오류가 발생했습니다.
Cloudflare 프록시는 클라이언트의 IP를 포함하는 CF-Connecting-IP 헤더를 추가해
Discourse의 nginx는 ngx_http_realip_module로 컴파일되어 있어 – 이 모듈은 해당 헤더를 읽고 실제 클라이언트 IP가 표시되도록 로그 등을 수정하는 소프트웨어야
set_real_ip_from은 전달된 IP 범위에서 오는 연결에 대해 이 기능을 활성화해. 보통은 Cloudflare의 IP 범위여야 하는데(cloudflare.template.yml 편의 템플릿이 공급), argotunnel을 사용하고 있으므로 argotunnel의 IP를 사용하면 돼.
services:
cloudflared:
image: cloudflare/cloudflared:latest
container_name: cloudflared
command: tunnel run
restart: unless-stopped
networks:
wan:
cf_tunnel:
# for ngx_http_realip_module
# set to a high IP so that hopefully docker doesn't DHCP assign
# another container that IP if it starts before cloudflared
ipv4_address: 10.200.10.200 # this is the ip for `set_real_ip_from` in nginx
volumes:
# should be owned by uid:gid 65532:65532
- ./conf:/home/nonroot/.cloudflared
networks:
cf_tunnel:
external: true # just means a network not managed by compose
# for performance:
# https://github.com/quic-go/quic-go/wiki/UDP-Receive-Buffer-Size
# sudo nano /etc/sysctl.conf
# add this line:
# net.core.rmem_max=2500000
# (my old value was 212992 – check it with: sudo sysctl net.core.rmem_max)
그 conf 디렉토리에 설정/인증서를 전달할 수 있어 (compose 파일의 주석처럼 chown을 기억해) 아니면 설정 절차를 다시 거치면 돼. 로그인 같은 cloudflared 명령은 이렇게 실행할 수 있어:
docker run -it --rm -v /path/to/conf:/home/nonroot/.cloudflared cloudflare/cloudflared:latest YOUR_CMD_HERE
그리고 discourse 컨테이너를 네트워크에 참여시켜야 해. 컨테이너 yml 파일 하단에 이렇게 해서 할 수 있어:
docker_args:
- '--network=cf_tunnel' # optionally, you could set a static IP here too
argo 서비스를 사용했습니다. 첫 달에 28유로를 지불하고 나서야 포기했죠. 실제로는 최소 200ms의 차이가 있었습니다. 하지만 매달 200ms를 위해 28유로를 지불할 수 없어서 해지했습니다. 더 큰 사이트라면 청구서가 더 많이 발생할 수 있다는 점을 염두에 두시기 바랍니다.
해당 사이트의 트래픽은 800~1,000명의 고유 사용자입니다. 이에 따라 계산해 보시면 됩니다.
아, 그거 64비트였네 ㅋㅋ. 근데 결국 해결했어. apt get upgrade를 실행하고 cloudflare 서비스를 재시작했더니 업로드가 됐거든. 그리고 cloudflare 터널로 영상 업로드에 제한이 있는지 알아? 20MB짜리 영상 업로드하는데 문제가 생기는데, 이전에는 없었거든.