카테고리 없음
nginx에서 여러 front build 파일 서비스 설정하기
daniel_lab
2023. 8. 22. 19:07
server {
~~~
location / {
root /home/ubuntu/~~/frontend;
index index.html index.htm;
try_files $uri /index.html @proxy;
}
location /slayer {
root /home/ubuntu/~~/frontend;
try_files $uri $uri/ /index.html;
}
~~~
}
location 부분엔 매칭되는 uri 패턴을 입력.
try files에는 도메인을 제외한 모든 uri 부분이 $uri 에 할당되며 이 uri 구조를 가지고 디렉토리 구조에 매핑해서 index.html을 찾는다는 설정. 즉, domain.com/slayer 이런 요청이었다면 $uri 에는 slayer 가 들어가며, 위에서 선언한 root 디렉토리 하위에 slayer 디렉토리 하위의 index.html을 찾게된다.
이걸 응용해서 여러 location 매칭패턴과 각 패턴에서의 build 파일 위치를 설정해주면 여러 프론트엔드 빌드파일을 서비스할 수 있는 간단한 구조가 완성