Skip to Content
Suffering builds character
아카이브8.Nginx특징정적 리소스 호스팅5. 스타일 시트를 적용하여 호스팅하기

5. 스타일 시트를 적용하여 호스팅하기

Nginx가 style.css 파일을 추가하여 호스팅할 수 있도록 적용

실습용 폴더 경로에 style.css 파일 생성

terminal
cd nginx-practice vi style.css

style.css 파일 내용(복사)

style.css
body { font-family: Arial, sans-serif; margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh; background: linear-gradient(135deg, #f06, #4a90e2); color: #fff; text-align: center; } .container { box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); padding: 20px 40px; background: rgba(0, 0, 0, 0.3); border-radius: 10px; } h1 { font-size: 2.5rem; margin-bottom: 10px; } p { font-size: 1.2rem; }

index.html 파일에 css <link> 추가

index.html
<!DOCTYPE html> <html lang="en"> <head>   <meta charset="UTF-8">   <meta name="viewport" content="width=device-width, initial-scale=1.0">   <title>My Custom Nginx Page</title>   <link rel="stylesheet" href="style.css"> </head> <body>   <div class="container">     <h1>Welcome to My Nginx Server!</h1>     <p>Your custom page is working perfectly.</p>   </div> </body> </html>

브라우저를 통해 접근하여 테스트 실행 결과
→ style.css 파일 자체는 잘 받아왔지만, 스타일이 적용되지 않았음

curl로 테스트

terminal
curl -I localhost/style.css
💡
Tip

-I, --head 옵션
HTTP 요청을 HEAD 메서드로 보내고, 응답 헤더만 출력, 본문(body)은 요청하지 않음

사용 상황
A. 파일이 실제로 서버에 있는지 확인하고, 다운로드는 하지 않을 때
B. Last-Modified, ETag, Cache-Control과 같은 캐싱 헤더 정보 확인할 때
C. Content-Type과 같은 MIME 확인할 때

실행 결과

terminal
HTTP/1.1 200 OK Server: nginx/1.26.2 Date: Sun, 12 Jan 2025 04:42:19 GMT Content-Type: text/plain Content-Length: 521 Last-Modified: Sun, 12 Jan 2025 04:40:45 GMT Connection: keep-alive ETag: "678347cd-209" Accept-Ranges: bytes

→ nginx가 스타일 시트를 응답할 때, Content-Type: text/plain 으로 응답하였음
결국 브라우저가 CSS 파일로 제대로 파싱을 수행하지 못하였고, 스타일 시트가 HTML 문서에 적용되지 않았음

Last updated on