Nginx 패치 요청이 잘못된 CORS 요청으로 종료됨

Nginx 패치 요청이 잘못된 CORS 요청으로 종료됨

간단한 설정입니다.

동일한 네트워크에 있는 세 개의 도커 컨테이너.

  1. ReactJs - nginx 서버의 프로덕션 빌드
  2. 스프링 부트
  3. MySQL

GET, POST 요청은 매력처럼 작동하지만 PATCH 요청을 사용하려고 하면 결국

잘못된 CORS 요청

2021/09/01 23:17:27 [notice] 31#31: *5 "/api/(.*)" matches "/api/task/assign/5/S01", client: 172.18.0.1, server: localhost, request: "PATCH /api/task/assign/5/S01 HTTP/1.1", host: "localhost", referrer: "http://localhost/operator/controlpanel"
2021/09/01 23:17:27 [notice] 31#31: *5 rewritten data: "/task/assign/5/S01", args: "", client: 172.18.0.1, server: localhost, request: "PATCH /api/task/assign/5/S01 HTTP/1.1", host: "localhost", referrer: "http://localhost/operator/controlpanel"
172.18.0.1 - - [01/Sep/2021:23:17:27 +0000] "PATCH /api/task/assign/5/S01 HTTP/1.1" 403 31 "http://localhost/operator/controlpanel" "Mozilla/5.0 (Windows NT xx; Win64; x64; rv:xx) Gecko/20100101 Firefox/91.0" "-"

내 nginx 구성

server {
  listen          80;
  server_name     localhost;
  expires -1;
  etag off;
  proxy_no_cache 1;
  rewrite_log on;

 location / {
   root /usr/share/nginx/html;
   try_files $uri /index.html;
 }

  location /api {
        rewrite /api/(.*) /$1  break;
        proxy_pass http://app:8080;
        proxy_pass_request_headers on;
        default_type  application/json;
  }
}

스프링 부트 종료 시 요청 정보를 받지 못했기 때문에 요청 정보를 스프링 서버로 보내기 전에 차단되었다고 가정합니다.

내가 뭘 잘못하고 있는지 아시나요?

답변1

앱에서 403 Forbidden 오류를 보냈으므로 뭔가 작업을 수행하고 있는 것 같습니다. 앱이 실제로 로깅 중인지 확인하세요. – Michael Hampton 2021년 9월 2일 16:13

어떤 이유로 봄은 그것을 로그에 넣지 않았습니다. 누군가 동일한 문제에 직면하면 cors 필터 전에 요청을 디버깅해 보십시오.

관련 정보