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??

7
  • 1
    Providing relevant logs would be very helpful. Otherwise we can only imagine.
    – nKn
    Commented Oct 24, 2019 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
    Commented Oct 24, 2019 at 13:35
  • 10.xxx.35.46 -> it is request addr. I hide it for security reasons
    – JYS
    Commented Oct 24, 2019 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
    Commented Oct 24, 2019 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
    Commented Oct 24, 2019 at 13:43

1 Answer 1

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.

2
  • Oh I use tomcat and java spring. not PHP.. But I need to check tomcat's max_thread value as you said. Thank you!
    – JYS
    Commented Oct 25, 2019 at 2:37
  • Ah yes, you're welcome! Commented Oct 25, 2019 at 6:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .