Spring Boot Admin Server, Client config 설정하기

이미지
 Spring Boot로 많은 프로젝트를 진행하게 됩니다. 많은 모니터링 도구가 있지만, Spring Boot 어플리케이션을 쉽게 모니터링 할 수 있는 방법을 소개하려고 합니다.   코드 중심으로 살펴보겠습니다. 1. 어드민 서버 구축 1-1. 디펜던시 추가 dependencies { // https://mvnrepository.com/artifact/de.codecentric/spring-boot-admin-starter-server implementation 'de.codecentric:spring-boot-admin-starter-server:2.5.4' } 1-2. 어드민 서버 설정 활성화 @SpringBootApplication @EnableAdminServer public class ServerApplication { public static void main (String[] args) { SpringApplication. run (ServerApplication. class, args) ; } } EnableAdminServer를 하면 됩니다. 2. 클라이언트 서버 설정  예제는 book-client, member-client 2가지 클라이언트, member-client가 2개의 인스턴스 실행으로 작성했습니다.  2-1 디펜던시 추가 dependencies { // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web implementation 'org.springframework.boot:spring-boot-starter-web:2.5.4' // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-actuator implementation 'org.spring...

nginx API Error JSON Response

  서버나 정적응답없이 nginx 즉시 오류를 응답하고 싶을 수 있습니다. 기본설정에는 root의 html 파일로 되어 있습니다. API의 웹서버로 사용하고 있는경우 Content-Type: application/json 의 json은 형식을 많이 사용합니다.

설정하기

nginx.conf

server {
listen
80;
server_name localhost; proxy_pass_header Server;
location /api { if ($host = 'api.mylocalhost') { return 404; }
proxy_pass http://127.0.0.1:8080;
} error_page 404 /404.json; location /404.json { return 404 '{"code": 404,"message": "Not Found"}'; }
}

404.json에서 json으로 확장자를 하는 이유는 response header에 Content-Type: application/json 가 자동으로 세팅되게 됩니다.

404 JSON 응답 이미지
응답 header Content-Type
호출하면 위와 같이 볼 수 있습니다.

그리고 if문 조건을 넣고 싶은경우 location 안에 추가해야합니다. if문 안에 location 을 추가하면 오류가 발생합니다.


이전 nginx 문서







댓글

이 블로그의 인기 게시물

Spring boot redis cache config

Spring boot redis RedisTemplate

MySQL PK 중복 (duplicate key ) 해결 방법