라벨이 nginx인 게시물 표시

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 가 자동으로 세팅되게 됩니다. 호출하면 위와 같이 볼 수 있습니다. 그리고 if문 조건을 넣고 싶은경우 location 안에 추가해야합니다. if문 안에 location 을 추가하면 오류가 발생합니다. 이전 nginx 문서 설치 및 실행  https://withccm.blogspot.com/2020/12/macos-nginx.html Response Header Server 정보 제거 https://withccm.blogspot.com/2022/07/nginx-response-header-server.html

nginx Response Header Server 정보 제거

이미지
nginx에 설정을 추가하지 않으면 현재 사용하고 있는 서버 정보가 노출됩니다. 이는 보안에 취약점이 될 수 있습니다. 설정하기 nginx.conf server { listen 80 ; server_name localhost ; proxy_pass_header Server; location / { proxy_pass http: //127.0.0.1:3000; } } 다음 설정을 추가하면 간단히 제거됩니다. nginx 설치, 실행은 다음 페이지를 참고해주세요. https://withccm.blogspot.com/2020/12/macos-nginx.html  

macOS nginx 설치, 실행, 설정 위치

macOS에서 nginx을 설치하려면 Homebrew가 먼저 설치되어야 합니다.  설치 방법은 앞선 포스팅을 참고바랍니다. https://withccm.blogspot.com/2020/12/macos-brew.html nginx 설치 Homebrew를 설치한 이후 brew 명령어를 사용하여 nginx를 설치합니다. brew install nginx m1 에서 안될때 brew install nginx Warning : No available formula with the name "nginx". ==> Searching for similarly named formulae... Error : No similarly named formulae found. ==> Searching for a previously deleted formula (in the last month)... Error : No previously deleted formula found. ==> Searching taps on GitHub... Error : No formulae found in taps. 위와 같은 오류 발생시 brew 코어 디렉토리를 삭제해 주면 해결됩니다. rm -rf $(brew --repo homebrew/core) 이후 설치하는데 시간이 좀 필요합니다. nginx 구동 명령어 nginx # 서버 시작 nginx -s stop # 서버 정지 nginx -t # 설정 테스트 nginx -s reload # 서버 재시작 nginx -t 를 사용하면 설정 수정후 에러가 있는지 미리 확인할 수 있는 유용한 명령어 입니다. nginx 설정파일 위치 /usr/local/etc/nginx or /opt/homebrew/etc/nginx 프록시 설정하기 nginx.conf server { listen 80 ; server_name localhost ; location / { ...