
๐ To Do List

๐ฉ๐ป๐ป Today I Learned ...
์ค๋ฌด์์๋ Swagger๋ฅผ ์จ๋ณด์ง ๋ชป ํด์ .. ์ฌ์ด๋ ํ๋ก์ ํธ์์ ์ฒ์ ๋์ ํ๋ฉด์ ๋ณด์ ์ฒ๋ฆฌ๋ฅผ ์ด๋ป๊ฒ ํ๋ ๊ฒ ์ข์์ง ๋ง๋งํ๋ค.
FE ๊ฐ๋ฐ์์ธ ์ง๊ฟํํ ๋ฌผ์ด๋ณด๋, ์ง๊ฟ์ ํ์ฌ์์๋ Nginx์์ ์ ๊ทผ ์ ํ์ ํ๊ณ ์๋ค๊ณ ์๋ ค์ค์ ๋๋ ์ ์ฉํด๋ดค๋ค !
TIL์๋ ๊ฐ๋จํ ๊ฐ๋ ์ ๋ฆฌ๋ง ํ๊ณ , ํธ๋ฌ๋ธ ์ํ ์ ํฌํจํ ์์ธํ ๋ด์ฉ์ ์ฌ์ด๋ ํ๋ก์ ํธ ๊ธฐ๋ก ์ผ์ง์ ์์ฑํ ์์ ์ด๋ค. โ๐ป
Nginx์ Basic Auth ์ ์ฉํ๊ธฐ
Basic Auth๋ ์๋ฒ์์ ์ธ๊ฐ๋์ง ์์ ์ฌ์ฉ์๋ค์ ์ ๊ทผ์ ์ ํํ ์ ์๋ ์ธ๊ฐ ์์คํ ์ ์๋ฏธํ๋ค.
Nginx์ basic Auth๋ฅผ ์ ์ฉํ๊ธฐ ์ํด์๋ nginx.conf ํ์ผ์ basic Auth์ ์ถ๊ฐํด์ฃผ๊ณ , ์์ด๋ ํจ์ค์๋ ๊ฐ์ด ๋ด๊ธด .htpasswd ํ์ผ์ ์์น๋ฅผ ์ง์ ํด์ฃผ๋ฉด ๋๋ค.
๋๋ ์๋์ฒ๋ผ Swagger ui์ ์ ์ํ์ ๋ ์์ด๋์ ํจ์ค์๋๋ฅผ ์ ๋ ฅํด์ ์ ๊ทผํ ์ ์๊ฒ ํ์๋ค.
location ~ ^/(swagger-ui|v3/api-docs) {
auth_basic "Restricted Access - Swagger";
auth_basic_user_file /etc/nginx/.htpasswd;
#.. ์๋ต
}
์ฐธ๊ณ :
[Nginx] Basic Auth
์ด๋ฒ๊ธ์์๋ nginx์ basic auth๋ฅผ ์ฌ์ฉํด ์ธ๊ฐ๋ ์ฌ์ฉ์์๊ฒ๋ง ์ ๊ทผ์ ํ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์์๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. 1. Basic Auth๋? nginx์์ ๊ฐ์ฅ ์์ฝ๊ฒ ์ฌ์ฉ์ ์ ๊ทผ์ ์ ํํ๋ ๋ฐฉ๋ฒ์ ๋๋ค. ๋ง
minholee93.tistory.com
Github Actions๋ก .htpasswd ์์ฑ
dev ์๋ฒ์์๋ ๋ณด์์ ์ ๊ฒฝ์ฐ๋ ๊ฒ ์ข์ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ด ๋ค์ด์ ์คํ๋ง ํ๋ก์ ํธ์ .htpasswd๋ฅผ ์ง์ ์์ฑํ์ง ์์๋ค.
Repository secrets์ ๋ก์ปฌ์์ ์์ฑํ ์์ด๋์ ํจ์ค์๋๋ฅผ ๋ฑ๋กํ ํ, workflow์ .htpasswd ์์ฑํด์ Docker image ๋น๋ํ๋ step์ ์ถ๊ฐํ๋ค.
1. .๋ก์ปฌ์์ htpasswd ์์ฑ
# htpasswd ์ค์น
# macOS
brew install httpd
# ์ฌ์ฉ์ ์ถ๊ฐ (๋น๋ฐ๋ฒํธ ํฌํจ)
htpasswd -cb .htpasswd {์์ด๋} {ํจ์ค์๋}
# ํ์ผ ํ์ธ
cat .htpasswd
// ํ์: username:encrypted_password
2. Repository secrets ์ถ๊ฐ
Base64 ์ธ์ฝ๋ฉ ๋ ์์ด๋์ ํจ์ค์๋ ๊ฐ์ ์ํฌ๋ฆฟ ๊ฐ์ ์ถ๊ฐํด์ค๋ค.
cat .htpasswd | base64 | tr -d '\n'
3. workflow ์์
.htpasswd ์์ฑํ๋ step์ ์ถ๊ฐํด์ค๋ค.
- name: Create .htpasswd file from secrets
run: |
echo "${{ secrets.HTPASSWD_BASE64 }}" | tr -d '\n' | base64 -d > ./nginx/.htpasswd
- name: Build Nginx Docker image (DEV)
uses: docker/build-push-action@v5
with:
context: .
file: ./nginx/Dockerfile
# .. ์๋ต
base64๋ก ์ธ์ฝ๋ฉํด์ ์ ์ฅํ๋ ์์ด๋์ ํจ์ค์๋๋ฅผ ๋์ฝ๋ฉํ์ฌ ๋น๋ ์ปจํ ์คํธ์ nginx ๋๋ ํฐ๋ฆฌ์ ์์ฑํ๋ฉด,
ํด๋น ํ์ผ์ ํฌํจํ Nginx ์ด๋ฏธ์ง๋ฅผ ๋น๋ํ๊ฒ ๋๋ค. Dockerfile์๋ ์๋ ๋ช ๋ น์ด๊ฐ ํฌํจ๋์ด ์์ด์ผ ํ๋ค.
COPY nginx/.htpasswd /etc/nginx/.htpasswd
๐ก Build Context : `docker build` ๋ช ๋ น์ด๋ฅผ ์คํํ์ ๋ ์ ๊ทผ ๊ฐ๋ฅํ ํ์ผ์ ์งํฉ
(์ค๋๋ ๋๊ผ์ง๋ง Docker ๊ณต๋ถ ๋ ์ด์ฌํ ํด์ผ๊ฒ ๋ค ... )
์ฐธ๊ณ :
[Docker] Build Context
Build contextLearn how to use the build context to access files from your Dockerfiledocs.docker.com docker buildx buildโdocker build ์ ๋ ๋ช ๋ น์ด๋ฅผ ์ํํ๋ฉด Dockerfile๊ณผ context๋ก๋ถํฐ Docker ์ด๋ฏธ์ง๊ฐ ๋ง๋ค์ด์ง๋ค. Build Context๊ฐ
mystudylog.tistory.com
์ฐ์ญ๊ณก์ ๋์ dev ๋ฐฐํฌ ์ฑ๊ณตํ๊ณ ์ํ๋ ๋๋ก ๋ณ๋์ ๋ก๊ทธ์ธ์ ํตํด Swagger UI์ ์ ๊ทผ ํ ์ ์๊ฒ ๊ตฌํํ๋ค. โ๐ป

'Today I Learned ๐ง' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [TIL-20260131] Docker ์ด๋ฏธ์ง ๋ค๋ฃจ๊ธฐ (0) | 2026.01.31 |
|---|---|
| [TIL-20260129] Docker ์ปจํ ์ด๋ ๋ค๋ฃจ๊ธฐ (0) | 2026.01.30 |
| [TIL-20260127] @AuthenticationPrincipal , Swagger JWT ์ธ์ฆ ์ค์ (0) | 2026.01.27 |
| [TIL-20260124] Spring Batch Reader ๊ตฌํ (0) | 2026.01.24 |
| [TIL-20260122] ํ๊ฒฝ์ ๋ฐ๋ฅธ ๊ฐ ์ค์ ํ๊ธฐ (Spring Environment, Kotlin buildList) (0) | 2026.01.22 |