4. 커스텀 페이지로 호스팅하기
Nginx가 제공하는 디폴트 페이지가 아닌 개발자가 작성한 페이지로 호스팅하기
기존에 존재하던 설정 파일 백업
terminal
cp nginx.conf nginx.conf.bak→ GUI말고 CLI를 통해 진행하기
설정 파일에 작성된 내용 초기화
terminal
echo "" > nginx.conf실습용 폴더 경로 생성 후 index.html 파일 생성
terminal
# 현재경로: C:\nginx
mkdir nginx-practice # ~은 생략 가능
cd nginx-practice
vi index.htmlindex.html 파일 내용(복사)
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>커스텀 Nginx 페이지</title>
</head>
<body>
<div class="container">
<h1>Welcome to My Nginx Server!</h1>
<p>Your custom page is working perfectly.</p>
</div>
</body>
</html>nginx/conf 경로 내 nginx.conf 파일의 내용 수정
nginx.conf
events {} # 연결 처리 설정 (기본값 사용)
http { # HTTP 요청 처리 설정 시작
server { # 서버 블록 시작
listen 80; # 80 포트에서 HTTP 요청 대기
server_name localhost; # 'localhost' 도메인에 대해 응답
root nginx-practice; # 정적 파일들이 위치한 루트 디렉토리
index index.html; # 기본 인덱스 파일 설정
} # 서버 블록 종료
} # HTTP 블록 종료nginx.conf에 작성한 설정 파일 문법이 유효한지 검증
terminal
nginx -t
# nginx: the configuration file C:\nginx/conf/nginx.conf syntax is ok
# nginx: configuration file C:\nginx/conf/nginx.conf test is successful→ 설정 파일이 문법 규칙을 준수하였음
작성한 내용으로 설정 파일 리로드
terminal
nginx -s reloadcurl이나 브라우저로 접근하여 테스트
terminal
curl localhost실행 결과

Last updated on