728x90
목차
개요
항상 프론트와 백엔드가 하나의 프로젝트에서 관리하는 방식으로 사용했다. 하지만 성능이나 확장성에서 MSA(Micro Achitecture)가 중시되면서 프론트와 백엔드를 분리하여 관리하는 추세이다. 백엔드는 jar파일로 실행하였지만 프론트는 찾아보니 dist파일을 NginX에서 실행할 수 있다는 것을 알게 되어 방법을 공유한다.
서버 환경
OS: CentOS Linux 7
NginX: 1.25.2
설치 환경설정
NginX를 설치하기 전 설정파일을 생성해야 한다.
1
|
]# vim /etc/yum.repos.d/nginx.repo
|
cs |
1
2
3
4
5
6
7
|
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
|
cs |
설정한 버전 선택
레포지토리 설정할 때 [nginx] → 하나만 설정하였기 때문에 생략해도 무방하다.
1
|
]# yum-config-manager --enable nginx
|
cs |
![](https://blog.kakaocdn.net/dn/cpoRRF/btsteAsX7cl/ltXmeKV97VjAATSC9XPh1k/img.png)
설치하기
dist 파일 실행 환경설정
1
|
]# vim /etc/nginx/conf.d/default.conf
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
server {
listen 8080;
server_name frontend_dev;
access_log /home/frontend/logs/access.log main;
error_log /home/frontend/logs/error.log warn;
root /home/frontend/dist;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/frontend/dist;
}
location ~ /\.ht {
deny all;
}
}
|
cs |
line 2, 'listen 8080;' : 실행할 포트 설정
line 5,6, 'access_log와 error_log' 변경할 로그 파일 위치 설정
line 8, 'root /home/frontend/dist;' : 자신의 프로젝트를 빌드해서 생성한 dist파일의 위치로 설정
line 9, 'index index.html' : 처음 실행할 파일
line 11, 13 : 되도록 똑같이 작성. 다르게 할 시 SPA 새로고침 404에러 이슈 발생할 수 있음
line 15, 20 : 에러 페이지 설정
line 22, 24 : htaccess 파일 접근 금지 설정
실행하기
1
|
]# systemctl start nginx
|
cs |
실행하면 403 Forbidden open() "/home/frontend/error.log/" is forbidden (13: Permission denied)가 발생할 수 있다. 이 경우에는 아래 명령어로 권한을 허용해주면 해결된다.
1
|
]# semanage permissive -a httpd_t
|
cs |
728x90
'Infrastructure > Linux' 카테고리의 다른 글
[Linux] brew 설치 방법 (1) | 2024.11.11 |
---|---|
[Linux] CentOS 7 - Git 설치 및 세팅 방법 (0) | 2024.02.17 |
jar 실행 시 nohup 종료되지 않고 프로세스 실행하는 법 (0) | 2023.03.24 |
Linux 외부 접근 IP 확인 명령어 (0) | 2023.03.20 |
리눅스 버전 확인 방법 (0) | 2023.03.20 |