NAS에 Nginx로 code-server 연동하기(작성중)

Seungrok Yoon (Lethe)·2025년 5월 29일
0

[TIL] 성장 한 스푼

목록 보기
55/55

기술 키워드: docker-compose, nginx, docker

지금 제가 소속되어 있는 회사는 참 작은 회사입니다. 저는 회사 내 유일한 개발자로 근무하고 있어요. 사실 개발만 하는게 아니고, 여느 인력이 부족한 작은 회사 직원들이 그렇듯이 물건 발주, 출장 등등 여러 일들도 같이 하고 있습니다.

제가 느낀 개발자가 적은 회사의 장점은 개발에 대한 지분이 높다보니, 자연스레 개발과 관련된 다양한 이슈들에 대한 결정을 스스로 생각하여 낼 수 있다는 점이었습니다. 단점은, 회사 내 가용자원이 넉넉하지 않다는 점입니다. 어떤 서비스를 개발하면서 이런저런 테스트를 하고 싶지만(특히 배포 관련), AWS, GCP같은 클라우드 인프라 서비스를 사용하고 싶다는 말 하기가 괜히 눈치보이더라구요ㅜㅜ.

그래도 회사에 NAS가 있고, 제 노는 노트북을 리눅스 머신으로 만들어놓았습니다. 나중에 본격적으로 AWS를 사용할 때에 대비해 docker와 linux환경에 익숙해질 순간에 대비해 이런저런 시도들을 해보고 있어요.

그 중 재밌었던(고통스러웠던) 작업은 NAS에 code-server를 설치하는 작업이었습니다. VScode에는 이미 ssh 터미널로 접근하는 기능이 있지만서도, code-server를 통해서 브라우저에서 바로 간단한 작업들은 처리하고 싶었어요. ssh 터미널로 접근할 때 저는 인증서 설정을 해둬서, 제 메인 랩탑이 아니면 ssh 터미널에 접근할 수가 없었거든요.

#Nginx 설정
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

# sent_http_set_cookie 변수를 추가하여 응답 헤더의 Set-Cookie를 로깅
log_format custom_combined '$remote_addr - $remote_user [$time_local] '
                          '"$request" $status $body_bytes_sent '
                          '"$http_referer" "$http_user_agent" "$http_x_forwarded_for" '
                          'response_cookies:"$sent_http_set_cookie"';

server {
    listen 8444 ssl;
    server_name hanbyoljireh.synology.me;

    ssl_certificate     /etc/nginx/certs/fullchain.pem;
    ssl_certificate_key /etc/nginx/certs/privkey.pem;
    ssl_protocols       TLSv1.2 TLSv1.3;
    ssl_ciphers         HIGH:!aNULL:!MD5;

    access_log /var/log/nginx/access.log custom_combined;

    # Portainer
    location /portainer/ {
        proxy_pass http://portainer:9000/;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_read_timeout 3600s;
        proxy_send_timeout 3600s;
        proxy_redirect http://portainer:9000/ /portainer/;
    }

# code-server
    location / {
        proxy_http_version 1.1;
        proxy_pass http://code-server:8080/;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Accept-Encoding gzip;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_redirect off;

    }
}


# docker-compose 설정
version: '3'
services:
  nginx:
    image: nginx:latest
    container_name: nginx
    restart: always
    ports:
      - "8444:8444"
    volumes:
      - /volume1/docker/nginx/conf.d:/etc/nginx/conf.d
      - /volume1/docker/nginx/certs:/etc/nginx/certs
    networks:
      - mynetwork
    depends_on:
      - portainer
      - code-server

  portainer:
    image: portainer/portainer-ce
    container_name: portainer
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /volume1/docker/portainer:/data
    networks:
      - mynetwork
    expose:
      - "9000"

  code-server:
    image: codercom/code-server:latest
    container_name: code-server
    restart: unless-stopped
    user: "1026:100" #=>이 부분은 사용자마다 다를 수 있어서 설정 전 확인 필요
    volumes:
      - /volume1/docker/code-server:/home/coder
    networks:
      - mynetwork
    expose:
      - "8080"
    environment:
      - TZ=Asia/Seoul
      - PASSWORD=871224
      - URL=주소
      - CSD_DIR=/home/coder

networks:
  mynetwork:
    driver: bridge

원래는 code-server도 portainer처럼, subpath - /code/를 통해 접근하게 만들고 싶었습니다만, websocket 에러가 자꾸 나는데, 아무리 프록시 헤더를 수정해도 해소되지 않았습니다.

https://github.com/coder/code-server/issues/4443

이 이슈였는데, 다들 루트경로로 location을 설정해둬서 저도 혹시나 해당 경로의 루트경로로 location을 변경하니 귀신같이 제대로 작동하더군요...

profile
안녕하세요 개발자 윤승록입니다. 내 성장을 가시적으로 기록하기 위해 블로그를 운영중입니다.

0개의 댓글

Powered by GraphCDN, the GraphQL CDN