서버를 만들어 보자
#!/bin/bash
REPOSITORY=[REPOSITORY 설정]
PROJECT_NAME=[project 이름]
cd $REPOSITORY/$PROJECT_NAME/
echo "> Git Pull"
git stash && git pull origin master && git stash pop
echo "> 기존 Build 경로의 jar 파일 삭제"
rm -rf $REPOSITORY/$PROJECT_NAME/build/libs/*.jar
echo "> 프로젝트 Build 시작"
./gradlew build
echo ">springboot_app 디렉토리로 이동"
cd $REPOSITORY
echo "> Build jar 파일 복사"
cp $REPOSITORY/$PROJECT_NAME/build/libs/*.jar $REPOSITORY/
echo "> 현재 구동중인 애플리케이션 pid 확인"
CURRENT_PID=$(pgrep -f ${PROJECT_NAME}.*.jar)
echo "현재 구동중인 어플리케이션 pid: $CURRENT_PID"
if [ -z "$CURRENT_PID" ]; then
echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다."
else
echo "> kill -15 $CURRENT_PID"
kill -15 $CURRENT_PID
sleep 5
fi
echo "> 새 어플리케이션 배포"
JAR_NAME=$(ls -tr $REPOSITORY/*.jar | tail -n 1)
echo "> JAR Name: $JAR_NAME"
echo "> $JAR_NAME 에 실행권한 추가"
chmod +x $JAR_NAME
echo "build 후 최근 파일 5개 제외하고 실행 jar 파일 삭제"
ls -td1 members-0.0.1*.jar | tail -n +6
ls -td1 members-0.0.1*.jar | tail -n +6 | xargs rm -f
echo "> $JAR_NAME 실행"
nohup java -jar $JAR_NAME &
배포를 할 수 있게 설정을 한다.
...
server {
listen 80;
listen [::]:80;
client_max_body_size 12000M;
server_name [도메인 주소]; ##localhost;
root [프로젝트 경로]; #최상위 문서 경로
return 301 https://$server_name$request_uri;
}
# HTTPS server
#
server {
listen 443 ssl;
listen [::]:443 ssl ;
client_max_body_size 5000M;
server_name [도메인 주소];
ssl_certificate [pem 위치]
ssl_certificate_key [key.pem 위치]
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
include /usr/local/nginx-1.20.1/conf.d/service-url.inc;
location / {
proxy_pass http://localhost:8083;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
}
}
...
8080포트에서 기존 레거시 프로젝트 사용하고 8083에 새로 추가해서 사용한다.