본문 바로가기

자유

서버 reverse proxy 단을 nginx에서 caddy로 변경합니다. (운영 노트)

Hide_D2022.09.06 02:13조회 수 394댓글 6

    • 글자 크기

별건 아니지만 나름 의미가 있을테니 설정을 남겨둡니다.

 

공용 Caddyfile

{
	#email

	log {
		output file /var/log/caddy/access.log
	}
}

(default_https_header) {
	header {
		# enable HSTS
		+Strict-Transport-Security "max-age=31536000; includeSubDomains"
		Location http:// https://
	}

	log {
		output file /var/log/caddy/access_https.log
	}

	encode zstd gzip
}

(default_proxy) {
	import default_https_header
	reverse_proxy {args.0} {
		header_up X-Real-IP {remote_host}
		header_down -Strict-Transport-Security
	}
}

 

sam.hided.net 쪽 caddy

sam.hided.net {
	import default_proxy localhost:80808800

	@mirror_mode {
		remote_ip #CIDR
	}

	reverse_proxy @mirror_mode localhost:80808800{
		header_up host sam-mirror.hided.net
		header_down -Strict-Transport-Security
		trusted_proxies #TODO:cidr 입력!
	}
}

sam-mirror.hided.net쪽 caddy

sam-mirror.hided.net {
	import default_https_header
	reverse_proxy https://sam.hided.net {
		header_up host sam.hided.net
		header_up X-Real-IP {remote_host}
		header_down -Strict-Transport-Security
		header_up -alt-svc
		header_down -alt-svc
		header_down -server
		header_up -upgrade-insecure-requests

		transport http {
			tls
			tls_renegotiation once
			versions 2 1.1
		}
	}
}

 

해결해야 했던 사안:

(1) 두개의 URL sam.hided.net 이 원래 서버, sam-mirror.hided.net 이 미러일 때, 제대로 host와 remote_addr이 지정되도록 해야함.

(2) 두 서버 모두 caddy를 사용해야함!

(3) http/3를 써보고 싶었기 때문에 tcp stream proxy는 배제함. (기존 nginx에서는 tcp stream proxy 사용)

 

 

핵심 해결책:

(1) sam-mirror - sam 통신에서 header의 host 조작을 왔다갔다 해야함

(2) reverse_proxy에서 trusted_proxies를 지정해야 HTTP_X_FORWARDED_FOR가 제대로 전달됨

 

 

 

수정 2022-09-21: Caddy 2.6에서는 HTTP/3를 기본 지원하므로 기존 config 수정

    • 글자 크기

댓글 달기

댓글 6
번호 분류 제목 글쓴이 최근 수정일 날짜
공지 관리/운영 60기 이벤트 이후 당분간 추가 기능 류의 작업이 늦춰집니다.6 Hide_D 2023.10.30 2023.08.02
748 건국선언 46기 건국 사스케 2022.07.02 2022.07.02
747 건국선언 46기 건국합니다! 장원영 2022.07.03 2022.07.03
746 개인열전 46기 레이스2 김나영 2022.07.28 2022.07.25
745 국가열전 46기 바나나제국 열전11 바나낫 2022.08.03 2022.07.26
744 개인열전 46기 사스케2 사스케 2022.07.28 2022.07.25
743 개인열전 46기 페이몬2 페이몬 2022.07.30 2022.07.26
742 개인열전 46기 평민킬러1 평민킬러 2022.07.28 2022.07.25
741 국가열전 47기 Jstris 열전7 나나 2022.08.12 2022.08.09
740 개인열전 47기 UK3 관흥 2022.08.24 2022.08.21
739 건국선언 47기 건국선언 사스케 2022.07.26 2022.07.26
738 건국선언 47기 건국합니다2 류화영 2022.07.25 2022.07.25
737 국가열전 47기 게판 국가열전8 미과 2022.08.21 2022.08.21
736 개인열전 47기 김나영3 김나영 2022.08.16 2022.08.15
735 개인열전 47기 불패1 불패 2022.08.21 2022.08.21
734 개인열전 47기 사스케1 사스케 2022.08.21 2022.08.21
733 개인열전 47기 우영우1 장원영 2022.08.21 2022.08.21
732 건국선언 47기 이상한변호사우영우 건국합니다9 장원영 2022.08.11 2022.07.25
731 개인열전 47기 임사영1 임사여엉 2022.08.21 2022.08.21
730 개인열전 47기 자택경비담당자1 앵벌스 2022.08.21 2022.08.21
729 개인열전 47기 천사소녀네티3 바나낫 2022.08.22 2022.08.21
이전 1 ... 8 9 10 11 12 13 14 15 16 17... 50다음
첨부 (0)