![`root` 지시문이 작동하려면 `try_files`가 필요한 이유는 무엇입니까?](https://linux55.com/image/132640/%60root%60%20%EC%A7%80%EC%8B%9C%EB%AC%B8%EC%9D%B4%20%EC%9E%91%EB%8F%99%ED%95%98%EB%A0%A4%EB%A9%B4%20%60try_files%60%EA%B0%80%20%ED%95%84%EC%9A%94%ED%95%9C%20%EC%9D%B4%EC%9C%A0%EB%8A%94%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
나는 nginx가 프론트엔드에서 정적 파일을 찾는 데 어려움을 겪고 있었습니다. try_files
모든 것이 작동하도록 겉보기에 동어반복적인 지시어를 추가했습니다.
location /frontend {
try_files $uri /;
}
root {{ static_root }};
index /frontend/index.html;
location / {
rewrite ^.*$ /frontend/index.html break;
}
내 질문은: 첫 번째 지시문 없이는 왜 이것이 작동하지 않습니까 location /frontend
?
답변1
이는 rewrite
무차별적이며 모든 요청( .css
파일 포함 .js
)에 적용됩니다. 별도의 location
URI를 추가하면 /frontend
로 시작하는 URI를 방지할 수 있습니다 rewrite
.
다음을 사용하여 비슷한 결과를 얻을 수 있습니다.
root /path/to/root;
location / {
try_files $uri $uri/ /frontend/index.html;
}
바라보다이 파일더 알아보기.