1. URI 경로별 라우팅 적용하기
localhost/index.html, style.css과 같이 정적 리소스는 잘 호스팅 되지만,
다음과 같이 다른 URI로 접근할 경우, nginx.conf 파일에 별도의 추가 설정이 없으면 Nginx는 해당 경로를 처리하지 못해 404 Not Found 를 반환함
terminal
curl localhost/hello # hello 경로로 요청
URI 경로별 라우팅 적용
nginx.conf 설정 파일의 내용을 다음과 같이 변경
nginx.conf
events {}
http {
include mime.types;
server {
listen 80;
server_name localhost;
root nginx-practice;
index index.html;
# location 블록을 통해 /hello로 요청 시 아래의 문자열을 응답하도록 지정
location /hello {
return 200 '/hello requested';
}
}
}1-1. 실행 결과
→ /hello 경로로 요청하였을 경우, 미리 작성해둔 문자열이 응답됨
Last updated on