Nginx

Nginx 入口 - 轉義字元

  • March 5, 2022

我有以下通過 nodePort 32100 公開的入口配置。當我呼叫(捲曲)URL

$$ 1 $$其中包含括號,我收到 HTTP 500 錯誤。但是當我呼叫 URL$$ 2 $$不包含括號,請求通過 NGINX 入口控制器(v0.35.0)成功傳遞。

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
 annotations:
   nginx.ingress.kubernetes.io/proxy-body-size: 0m
   name: test1-app-ingress
 namespace: test1
spec:
 rules:
 - host: ing1.example.com
   http:
     paths:
     - backend:
         serviceName: test1-app-1-ingress
         servicePort: 80
       path: /test1
 - host: ing2.example.com
   http:
     paths:
     - backend:
         serviceName: test1-app-2-ingress
         servicePort: 80
       path: /test1

$$ 1 $$

curl  "http://ing1.example.com:32100/test1/test1.json/Streams(Type_4000000)" -X POST --data-binary @25kfile 
* About to connect() to ing1.example.com port 32100 (#0)
*   Trying 10.10.10.30...
* Connected to ing1.example.com (10.10.10.30) port 32100 (#0)
> POST /test1/test1.json/Streams(Type_4000000) HTTP/1.1
> User-Agent: curl/7.29.0
> Host: ing1.example.com:32100
> Accept: */*
> Content-Length: 25000
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< HTTP/1.1 500 Internal Server Error
< Server: nginx
< Date: Tue, 01 Mar 2022 20:08:07 GMT

應用程序日誌:

10.113.4.0 - - [01/Mar/2022:20:08:07 +0000] "POST /test1/test1.json/Streams(Type_4000000) HTTP/1.0" 500 528 "-" "curl/7.29.0" 25283 0.004 [test1-test1-app-1-ingress-80] [] 10.113.4.157:80 528 0.003 500 4b3fd4d41fb8a2d26691bd2da78f24b

$$ 2 $$

curl  "http://ing1.example.com:32100/test1/test1.json/StreamsType_4000000" -X POST --data-binary @25kfile 
* About to connect() to ing1.example.com port 32100 (#0)
*   Trying 10.10.10.30...
* Connected to ing1.example.com (10.10.10.30) port 32100 (#0)
> POST /test1/test1.json/StreamsType_4000000HTTP/1.1
> User-Agent: curl/7.29.0
> Host: ing1.example.com:32100
> Accept: */*
> Content-Length: 25000
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Server: nginx
< Date: Tue, 01 Mar 2022 20:09:59 GMT

應用程序日誌:

172.28.120.65 - - [01/Mar/2022:20:09:59 +0000] "POST /test1/test1.json/StreamsType_4000000 HTTP/1.0" 200 0 "-" "curl/7.29.0" 25281 0.003 [test1-test1-app-1-ingress-80] [] 10.113.4.157:80 0 0.003 200 133bbb4f7149d31e75cf78158566efee

這是 NGINX IC 的問題嗎?我應該轉義入口配置上的任何字元,比如括號嗎?

應用程序的日誌文件表明請求到達了應用程序。這意味著“500”錯誤程式碼是由應用程序發送的。因此,您無法在 nginx 端做任何事情來解決這種情況。

您需要確保應用程序正確處理請求。

引用自:https://serverfault.com/questions/1095107