# CF의 real ip를 추가하면 rebuild가 안 되는 이유를 분석해 주실 수 있나요?

**URL:** https://meta.discourse.org/t/cf-real-ip-rebuild/303509
**Category:** Self-hosting
**Tags:** cdn
**Created:** [4월 12, 2024, 3:23오전 UTC](https://meta.discourse.org/t/cf-real-ip-rebuild/303509 "2024-04-12T03:23:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![5804829](https://avatars.discourse-cdn.com/v4/letter/5/7cd45c/32.png) [@5804829](https://meta.discourse.org/u/5804829)
#### Post date: [4월 12, 2024, 3:23오전 UTC](https://meta.discourse.org/t/cf-real-ip-rebuild/303509/1 "2024-04-12T03:23:00Z")

</div>

첨부 파일에 설치 로그가 있습니다.  
첨부된 설치 로그입니다

app.yml에 - "templates/cloudflare.template.yml"를 추가했습니다  
[log.txt](https://meta.discourse.org/uploads/short-url/g06icWMnIYGfMxzm1P7aW3IjRSt.txt) (167.9 KB)

---

<div class="post-metadata">

### Author: ![5804829](https://avatars.discourse-cdn.com/v4/letter/5/7cd45c/32.png) [@5804829](https://meta.discourse.org/u/5804829)
#### Post date: [4월 12, 2024, 3:27오전 UTC](https://meta.discourse.org/t/cf-real-ip-rebuild/303509/5 "2024-04-12T03:27:45Z")

</div>

```plaintext
[root@iZj ~]# docker info
Client: Docker Engine - Community
 Version: 26.0.1
 Context: default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version: v0.13.1
    Path: /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version: v2.26.1
    Path: /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 5
  Running: 0
  Paused: 0
  Stopped: 5
 Images: 5
 Server Version: 26.0.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: false
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: e377cd56a71523140ca6ae87e30244719194a521
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 5.10.134-16.3.al8.x86_64
 Operating System: Alibaba Cloud Linux 3 (Soaring Falcon)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.499GiB
 Name: iZj6cdtkubp4jn6i3drnbzZ
 ID: 7196760b-fdec-4e69-8758-9186040c032c
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

```

```plaintext
[root@iZj ~]# free -m
              total used free shared buff/cache available
Mem: 3583 224 2582 2 776 3124
Swap: 0 0 0

```

```plaintext
[root@iZj~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs 1.8G 540K 1.8G 1% /run
tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
/dev/vda3 79G 19G 57G 25% /
tmpfs 1.8G 0 1.8G 0% /tmp
/dev/vda2 200M 5.8M 195M 3% /boot/efi
tmpfs 359M 0 359M 0% /run/user/0

```

이 VPS는 2코어, 4기가바이트 RAM입니다.  
재빌드할 수 없습니다. Cloudflare에 연결되어 있고 실제 IP를 표시하려고 하고 있기 때문입니다.  
"templates/cloudflare.template.yml"을 추가했습니다.  
재빌드할 수 없습니다.

---

<div class="post-metadata">

### Author: ![fokx](https://avatars.discourse-cdn.com/v4/letter/f/958977/32.png) [@fokx](https://meta.discourse.org/u/fokx)
#### Post date: [4월 12, 2024, 8:29오전 UTC](https://meta.discourse.org/t/cf-real-ip-rebuild/303509/6 "2024-04-12T08:29:50Z")

</div>

로그에 따르면 `/tmp/add-cloudflare-ips` 단계 실행 실패가 원인인 것으로 보이지만, 해당 스크립트 중 정확히 어떤 명령문이 실패했는지는 찾을 수 없습니다.

```plaintext
Pups::ExecError: /tmp/add-cloudflare-ips failed with return #<Process::Status: pid 4229 exit 8>
Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params "/tmp/add-cloudflare-ips"
bootstrap failed with exit code 8

```

`app.yml`에서 cloudflare 관련 라인을 제거한 후, 리빌드(rebuild)가 완료되면 컨테이너에 진입하여 `templates/cloudflare.template.yml`의 명령어를 수동으로 단계별로 실행해 보세요. 완료된 후에는 `nginx -s reload`를 실행하면 됩니다. 제 경험상 네트워크 문제로 인해 wget이 실패했을 가능성이 높습니다.

```plaintext
run:
  - file:
      path: /tmp/add-cloudflare-ips
      chmod: +x
      contents: |
        #!/bin/bash -e
        # Download list of CloudFlare ips
        wget -q https://www.cloudflare.com/ips-v4/ -O - > /tmp/cloudflare-ips
        echo >> /tmp/cloudflare-ips
        wget -q https://www.cloudflare.com/ips-v6/ -O - >> /tmp/cloudflare-ips
        # Make into nginx commands and escape for inclusion into sed append command
        CONTENTS=$(</tmp/cloudflare-ips sed '/^$/d; s/^.*/set_real_ip_from &;/' | tr '\n' '\\' | sed 's/\\/\\n/g')
        
        echo CloudFlare IPs:
        echo $(echo | sed "/^/a $CONTENTS")
        # Insert into discourse.conf
        sed -i "/sendfile on;/a $CONTENTS\n" /etc/nginx/conf.d/discourse.conf
        #sed -i "/sendfile on;/a $CONTENTS\nreal_ip_header CF-Connecting-IP;" /etc/nginx/conf.d/discourse.conf
        # Clean up
        rm /tmp/cloudflare-ips

  - exec: "/tmp/add-cloudflare-ips"
  - exec: "rm /tmp/add-cloudflare-ips"

```

---

<div class="post-metadata">

### Author: ![5804829](https://avatars.discourse-cdn.com/v4/letter/5/7cd45c/32.png) [@5804829](https://meta.discourse.org/u/5804829)
#### Post date: [4월 12, 2024, 3:25오후 UTC](https://meta.discourse.org/t/cf-real-ip-rebuild/303509/7 "2024-04-12T15:25:18Z")

</div>

VPS에는 반드시 스왑이 있어야 하나요? 제 VPS는 메모리가 작아서 기본적으로 스왑이 없습니다.

---

<div class="post-metadata">

### Author: ![fokx](https://avatars.discourse-cdn.com/v4/letter/f/958977/32.png) [@fokx](https://meta.discourse.org/u/fokx)
#### Post date: [4월 12, 2024, 4:22오후 UTC](https://meta.discourse.org/t/cf-real-ip-rebuild/303509/8 "2024-04-12T16:22:20Z")

</div>

실패 원인이 메모리/스와프와 관련이 있는 것도 아닌데 말이죠.

또한, 질문하신 문제는 다른 분들도 경험해 본 적이 있습니다. 질문하기 전에 먼저 검색해 보시기 바랍니다. 사실 아래 Related(관련) 섹션에 이미 지능형 추천이 되어 있습니다. 예를 들어: [Failed to bootstrap (/tmp/add-cloudflare-ips)](https://meta.discourse.org/t/failed-to-bootstrap-tmp-add-cloudflare-ips/221667/)
