![Nginx 補丁請求以無效的 CORS 請求結束](https://rvso.com/image/770085/Nginx%20%E8%A3%9C%E4%B8%81%E8%AB%8B%E6%B1%82%E4%BB%A5%E7%84%A1%E6%95%88%E7%9A%84%20CORS%20%E8%AB%8B%E6%B1%82%E7%B5%90%E6%9D%9F.png)
設定很簡單。
同一網路中的三個 docker 容器。
- ReactJs - 在 nginx 伺服器上進行生產構建
- 春季啟動
- 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 錯誤,因此它一定正在執行某些操作。確保您的應用程式確實正在記錄日誌。 – 麥可漢普頓 2021 年 9 月 2 日 16:13
由於某種原因,spring 沒有將其放入日誌中。如果有人遇到相同的問題,請嘗試在 cors 過濾器之前偵錯請求。