Request.urlopen does not work after moving the server to the cloud. use docker-compose django, nginx

Yesterday, I moved to the cloud while running the server locally. Based on ubuntu 20, the server is operated using docker, django, nginx, mariadb, certbot in docker-compose. is configured and operational. It has opened both 80:port and 443post to the cloud, and outbound is allowed in the cloud itself. In docker-compose, if you receive a request from 80 or 433 from nginx.conf to upstream django_nginx server container name: 8000 after mapping from docker-compose to 80 or 433 for the application --bind 0.0.0.0:8000 Jango. Proxy_pass http://django_nginx; is passing. The problem is that when an external api is called from a running django inside the docker container (e.g. request.urlopen(url) header included or not included), there is no response. So I gave the option request.url, timeout=3 and checked, and the https request causes We failed to reach a server /Reason: _ssl.c: 980: The handshake operation timed out http request causes We failed to reach a server /Reason: timed out. I used to run a server locally as a virtual machine, but it was a logic that was going on without a problem before, so I'm very embarrassed because it didn't work after the cloud transfer. I'm inquiring because I haven't made any progress even though I've tried many things. Is there anything I'm missing? All logic works normally except for API calls. If you request curl from the command line, the response will return normally. plz help

fort enter image description here

error enter image description here

mycode enter image description here

docker-compose

version: '3'   
    
services:

  nginx:
    container_name: insaengsikdang_nginx
    build: ./nginx
    volumes:
      - static_volume:/srv/prod/_static
      - media_volume:/srv/prod/_media
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
    environment:
        - TZ=Asia/Seoul
        # - PROXY_CONNECT_TIMEOUT=460s
        # - PROXY_READ_TIMEOUT=460s
    ports:
      - 80:80
      - 443:443
    depends_on:
      - insaengsikdang_django
    restart: always

  certbot:
    image: certbot/certbot
    entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 24h & wait $${!}; done;'"
    volumes:
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
    environment:
        - TZ=Asia/Seoul
    # depends_on:
    #   - nginx
  
  django:
      container_name: insaengsikdang_django
      build: ./mysite
      image: mysite/django:4.0.3
      restart: always
      # command: python manage.py runserver 0.0.0.0:8000
      command: gunicorn --timeout 5000 insaengsikdang.wsgi:application --bind 0.0.0.0:8000
      volumes:
        - ./mysite:/srv/test-server
        # - ./log:/var/log/uwsgi
        - static_volume:/srv/prod/_static
        - media_volume:/srv/prod/_media
      environment:
        - TZ=Asia/Seoul
      depends_on:
        - db
      expose:
        - 8000
      env_file:
        - ./mysite/.env.prod
  db:
      container_name: insaengsikdangdb
      image: mariadb:10.6.7
      restart: always
      expose:
        - "3306"
      volumes:
        - /insaengsikdangdb/insaengsikdangdb_local:/var/lib/mysql/
      environment:
        - TZ=Asia/Seoul
      env_file:
        - ./mysite/.env.prod.db
volumes:
  static_volume:
  media_volume:

nginx.conf


upstream insaengsikdang_nginx {
    server insaengsikdang_django:8000;
}

server {
    listen 80;
    server_name ceo.insaengsikdang.com;

    location / {
        return 301 https://$host$request_uri;
    }

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }
}
server {
    listen 443 ssl;
    server_name ceo.insaengsikdang.com;

    client_max_body_size 3m;

    location / {
        proxy_pass http://insaengsikdang_nginx;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
        proxy_connect_timeout 360s;
        proxy_read_timeout 360s;
        proxy_send_timeout 360s;
    }

    location /static/ {
        alias /srv/prod/_static/;
    }

    location /media/ {
        alias /srv/prod/_media/;
    }

    ssl_certificate /etc/letsencrypt/live/ceo.insaengsikdang.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/ceo.insaengsikdang.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
    
}

header change nginx code change django port change 8000>80 curl https://apis.tracker.delivery/carriers/kr.lotte/tracks/104222276804 port change docker-compose version change 3.0 > 3.8 django ALLOWED_HOSTS delete localhost, and 127,0,0,1 insaert my cloud ip

Back to Top