'Docker Nginx reverse proxy not working after adding iptables rules for cloudflare

I am running docker compose with my app(python+nginx) & nginx as reverse proxy. My app is exposed via port 80 but only on container not on host. Only nginx(reverse proxy) is mapped to port 80 on host. So, basically connection comes to port 80(docker - nginx reverse proxy), then it proxy_pass http://my-app:80; to my app.

But when I add Docker container accessible only via Cloudflare CDN (selected ip ranges) . Connection is received by nginx reverse proxy but never forwarded to my app.

access.log

172.70.75.36 - - [09/May/2022:09:07:44 +0000] "GET / HTTP/2.0" 504 167 "-" "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0" "102.156.50.161"

error.log

2022/05/09 09:15:08 [error] 10#10: *178 upstream timed out (110: Connection timed out) while connecting to upstream, client: 172.70.150.182, server: apleeandorgae.com, request: "GET / HTTP/2.0", upstream: "http://172.18.0.8:80/", host: "apleeandorgae.com"

admin@ubuntu: $ sudo ip addr show dev docker0
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:9e:a1:d1:ae brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source