Search

#008 #location 라우팅

ex05 : 로케이팅

Dockerfile 생성
HTML 폴더 생성

Dockerfile 작성

FROM nginx COPY html /usr/share/nginx/html COPY conf/nginx.conf /etc/nginx/conf.d/default.conf ENTRYPOINT ["nginx", "-g", "daemon off;"]
JavaScript
복사
전체 동작 설명
1.
이미지 기반 설정: nginx 이미지를 기반으로 새로운 이미지를 빌드
2.
정적 파일 복사: 현재 빌드 컨텍스트의 html 디렉토리 안에 있는 모든 파일을 /usr/share/nginx/html 디렉토리로 복사하여 Nginx가 이 파일들을 서빙
3.
Nginx 설정 파일 복사: 현재 빌드 컨텍스트의 conf/nginx.conf 파일을 Nginx 설정 파일로 복사하여 Nginx의 동작을 설정.
4.
엔트리포인트 설정: 컨테이너가 시작될 때 Nginx를 포그라운드 모드에서 실행하여 컨테이너가 종료되지 않도록 함

nginx.conf 구조

location 에서 / 요청이 들어오면 root로 가서 index를 실행한다는 라우팅이 가능하다.
conf폴더 생성 50x.html 생성

nginx.conf 전체코드

server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} }
JavaScript
복사

index.html 전체 코드

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <h1>Welcome Nginx</h1> </body> </html>
JavaScript
복사
다시 작성해서 실행
루트 경로 / 로 요청했는데도, 페이지가 잘 반환되었다. 에러페이지 자동 라우팅은 잘 모르겠다.