IT

reactjs nextjs nginx setting

roselumi 2023. 6. 14. 10:10

좌충우돌 했던 설정.. 한방에 정리한다.
나같은 경우는 localhost에 8089 3000 8081 3개의 포트가 있는데 각각 아래와 같음
8089: nginx static server
3000: nextjs front server
8081: back end server
결론적으로, nextjs를 사용하면서 서버 하나 더 추가
nextjs의 SSR관련 로직을 빌드할 때 SSG로 바꿔주는 설정이 있다고 한다. 친구한테 들음. 이런게 있다니 신기함.

1. nginx setting
nginx.conf
location: D:\nginx\conf\nginx.conf
contents: nginx.conf 파일 참고

nginx.conf
0.00MB

2. react setting
2-1. 무중단 배포를 위한 pm2 설치
2-2. yarn or npm(나같은 경우는 yarn을 사용) yarn add pm2
2-3. 설치 되면 프로젝트 루트 폴더에 server.js and ecosystem.config.js 파일 추가(파일은 첨부함)

ecosystem.config
0.00MB
server.js
0.00MB

pm2 start ecosystem.config.js 프롬프트창에 실행시켜 잘되는지 확인한다.  ecosystem.config.js에 포트 관련 설정 있을거임 PORT: 3000 이런식으로...

아래는 내 깃 소스코드 주소
https://github.com/leesangdoc/ucb_front.git