본문 바로가기

자유

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

Hide_D2022.09.06 02:13조회 수 401댓글 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
232 자유 블랙홀 게시판 생성기념16 미과 2024.06.14 2024.06.08
231 자유 여러분1 페브리 2024.06.08 2024.06.08
230 자유 장원영 님의 질문에 대한 답변 정리5 無名別動隊(슈퍼블루문) 2024.06.08 2024.06.08
229 자유 잉여 유저의 잡생각2 니쉬 2024.06.07 2024.06.07
228 자유 [납량특집] 무서운 한 이야기2 페브리 2024.06.07 2024.06.07
227 자유 이해하면 무서운 이야기 #1 사스케 2024.06.07 2024.06.07
226 자유 히데님 의견이나 유저분들 의견듣고 싶어요 (신고는 아닙니다)27 페브리 2024.06.08 2024.06.07
225 자유 저격 유닠이 발동을 안합니다 ㅠ6 Mella 2024.06.08 2024.06.07
224 자유 관우와 보정스님4 이해고 2024.06.07 2024.06.06
223 자유 저런2 페브리 2024.06.06 2024.06.06
222 자유 산해경 좀 이상한 것 같습니다.4 블랙죠 2024.06.05 2024.06.05
221 자유 떠돌이 의사 치료1 류화영 2024.06.02 2024.06.02
220 자유 자게2 블랙죠 2024.06.02 2024.06.02
219 자유 자게가 대학교 시절이 생각나요3 페브리 2024.06.02 2024.06.02
218 자유 슈퍼블루문 vs3 블랙죠 2024.06.01 2024.05.30
217 자유 다들 진정하시고 커피나 한잔하시죠..5 POCARI 2024.05.30 2024.05.30
216 자유 이게 메모장이야 커뮤니티야2 갓세정 2024.05.30 2024.05.30
215 자유 메세지 vs 메시지2 페브리 2024.05.30 2024.05.30
214 자유 장난하나3 류화영 2024.05.30 2024.05.30
213 자유 false 블랙죠 2024.05.30 2024.05.30
이전 1 2 3 4 5 6 7 8 9 10... 12다음
첨부 (0)