Programming/Docker

docker compose를 이용해서 한 번에 서버 구축하기 (4) nginx-proxy 와 let's encrypt

stein 2021. 9. 8. 17:53
  1. nginx-proxy docker에서는 하위 url을 판단해서 분기하는게 불가능 할 듯하다. sub-domain으로 분리해야할 듯 하다
    1. nginx-proxy docker 내부의 /etc/nginx/conf.d/default.conf 파일
    2. 다음과 같이 변경했다
      접속이 된다
      변경된 /etc/nginx/conf.d/default.conf
      dapadastock.com/api 이런식으로 VIRTUAL_HOST를 설정했지만, host자체를 dapadastock.com/api로 보더라. (url로 api가 들어온 것이 아니라) 따라서 동작하지 않았다.
  2. 여기 이 부분의 왼쪽 volume이 뭘 의미하는지 모르겠다. 임의로 알아서 넣으라는 건지, 실제로 저런 공간이 존재하는 건지...
    1. 최초에는 이렇게 폴더를 다 만들어서 이어줬다(뭔지 모르니까;;

    2. 그랬더니 django에서 static 파일이 전달되지 않는다.(default 파일에 static 경로가 명시되어있음)
    3. 그래서 volume을 다음과 같이 mount했다
    4. 잘 된다.
    5. jrcs/letsencrypt-nginx-proxy-companion 포스트에 있는 이 이미지는 deprecated되었다.
      1. NGINX_PROXY_CONTAINER=nginx-proxy
      2. 해당 이미지에 env로 위 변수를 넣어주는데 저거 넣으니 docker-gen의 container id를 못찾는 에러가 뜬다
      3. nginx-proxy-letsencrypt_1 | jq: error (at <stdin>:1): Cannot iterate over null (null) nginx-proxy-letsencrypt_1 | Error: can't get docker-gen container id ! nginx-proxy-letsencrypt_1 | If you are running a three containers setup, check that you are doing one of the following : nginx-proxy-letsencrypt_1 | - Set the NGINX_DOCKER_GEN_CONTAINER env var on the letsencrypt-companion container to the name of the docker-gen container. nginx-proxy-letsencrypt_1 | - Label the docker-gen container to use with 'com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen'.
      4. 여기서 docker-gen이 뭔가 해서 계속 찾아봤는데 nginx-proxy가 내부적으로 돌리는 어플인것 같다
      5. 그래서 공식 docker-hub가서 설명을 보니 해당 환경변수 설정 자체가 없어서 없애니 에러가 해결됨
  3. 80 포트를 전체로 열지 않아서 인증과정이 pending 되었었음
  4. 443 포트를 열지 않아서 접속이 되지 않았었음
  5. 와일드 카드 형식으로 certification이 되는게 아니다. api.dapadastock.com도 host이름을 모두 적어줘야한다.

  6. 완료!