1

I have a problem that nginx returns 501 error or 200 OK for same requests. I don't know why.

I guess nginx doesn't have enough connections for upstream.(I connect nginx and tomcat by reverse proxy. using upstream.) So it returns 501. I know it will return 502 not 501 in this case. But I think it is weird "sometimes" nginx returns 501 error for same requests. not "always". They are exactly same requests. Same url, header, and body.

So I tried to increase "keepalive_requests", "keepalive_timeout" and "keepalive"(for upstream). The frequency has been reduced but not completely eliminated.

Please help me....

access.log

10.xxx.35.46 - [24/Oct/2019:22:33:01 +0900] "GET /monitor/l7check HTTP/1.1" [-] - [501] 1120 0.001 "-" "-"
10.xxx.35.46 - [24/Oct/2019:22:33:06 +0900] "GET /monitor/l7check HTTP/1.1" [-] - [200] 31 0.002 "-" "-"

I found why tomcat returns 501! But still I don't know why it happens.

nginx access.log

10.33.xxx.xxx - [25/Oct/2019:16:21:19 +0900] "POST /ajax/test?ts=1571988079124 HTTP/1.1" [501] 1147 0.006 "https://test.com" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36"

tomcat access.log

127.0.0.1 - - [25/Oct/2019:16:21:19 +0900] "01POST /ajax/test?ts=1571988079124 HTTP/1.1" 501 1147 "https://test.com" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36"

As you can see, client requests POST method but tomcat receives 01POST method.

I try to set proxy method to request method like this.

proxy_method $request_method;

But it doesn't work. It still happens. Why does nginx(or tomcat??) change method??

JYS
  • 11
  • 3
  • 1
    Providing relevant logs would be very helpful. Otherwise we can only imagine. – nKn Oct 24 '19 at 13:14
  • access.log 10.xxx.35.46 - [24/Oct/2019:22:33:01 +0900] "GET /monitor/l7check HTTP/1.1" [-] - [501] 1120 0.001 "-" "-" 10.xxx.35.46 - [24/Oct/2019:22:33:06 +0900] "GET /monitor/l7check HTTP/1.1" [-] - [200] 31 0.002 "-" "-" – JYS Oct 24 '19 at 13:35
  • 10.xxx.35.46 -> it is request addr. I hide it for security reasons – JYS Oct 24 '19 at 13:39
  • And `error.log`? it would be better if you edited your question and post all the logs in the formatted style. – nKn Oct 24 '19 at 13:40
  • there is no error log for this. I saw error log as debug mode. But there is no specific errors for this. It seemed success before request went to upstream server(tomcat). Because I can't find its any logs(return 501 error) in catalina.out – JYS Oct 24 '19 at 13:43
  • I don't know Tomcat, but does it generate any logs? If Nginx generated the 5xx error (rather than just passing it through from upstream), it should write an entry in its error log. Which leads me to suspect that the error originates from Tomcat. – Richard Smith Oct 24 '19 at 14:00
  • I don't have any error log for Tomcat. In my team, we only check catalina.out log(logging for standard output or error). But there is no access log if it returns 501 error. I think it would be better to add access log for tomcat as you said. Thank you! – JYS Oct 25 '19 at 02:36

1 Answers1

1

Do you use PHP-FPM? Than it's possible that you should increase to something like:

pm.max_children = 500
pm.max_requests = 1000

I have seen this a lot with 501 errors. Default is 50 for max_childeren, by far not enough.

Erjen Rijnders
  • 356
  • 1
  • 5