unit: "Error 400" in Cloud Foundry?

I’ve been trying to deploy a custom Docker container with Nginx Unit in a Cloud Foundry instance, but the only response I get is “Error 400” across the line.

Can someone tell me if this is generated by Nginx Unit?

<!DOCTYPE html><title>Error 400</title><p>Error 400.

I turned on the Unit access logs, but I only see this:

10.244.112.49 - - [02/Apr/2020:13:26:06 +0000] "GET / HTTP/1.1" 400 54 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"

The Cloud Foundry router reports something similar:

[2020-04-02T13:26:05.921827769Z] "GET / HTTP/1.1" 400 0 54 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36" "10.164.95.242:33022" "158.176.87.28:61022" x_forwarded_for:"77.56.208.204, 10.164.95.242" x_forwarded_proto:"http" vcap_request_id:"f0b4325d-7dac-487f-42d5-f2c1f1ead485" response_time:0.120993 gorouter_time:0.000282 app_id:"02b6df87-2617-4b4f-8b1e-67abd17984b6" app_index:"0" x_global_transaction_id:"f28b14df5e85e7edc32d031d" true_client_ip:"-" x_b3_traceid:"3ff4a457fc085864" x_b3_spanid:"3ff4a457fc085864" x_b3_parentspanid:"-" b3:"3ff4a457fc085864-3ff4a457fc085864"

In order to compare, I have deployed the official Unit Docker image in the same way, and configured it live over SSH, only to get the same “Error 400” again.

The configuration which I used with the official image is very simple:

cat << EOF > config.json
{
    "listeners": {
        "*:8080": {
            "pass": "routes"
        }
     },
    "routes": [
        {
            "action": {
                "share": "/var/www/static"
             }
        }
    ],
    "access_log": "/var/log/access.log"
}
EOF

As soon as I curl the configuration into Unit, I get confirmation:

{
        "success": "Reconfiguration done."
}

Before the configuration is live, I get a “502 Bad Gateway”—which is to be expected—in Cloud Foundry’s typical response format, then afterwards “Error 400” is back. This response does not appear as if it was generated by Cloud Foundry.

I can still curl from inside the live container to get a proper application response, as there seems to be a working service listening on 0.0.0.0:8080. And just running the container bare on the OS also works.

I wonder what happens when the request traverses through the system [HTTP Client] -> [Cloud Foundry Router] -> [Nginx Unit]. Is there any way to get a dump of this request from Unit?

Your help would be appreciated!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

@VBart Thank you for pointing out my mistake!

I did not take Bash shell parameter expansions into account, when I tested this locally… 🙄

I deployed the container directly to the IBM cloud and I can confirm it works perfectly!

@dannmartens you have to escape $ in your curl command: curl -H "\$wssn: 80" localhost:9090

Оtherwise curl sends a header field with empty name:

% curl -v -H "$wssn: 80" 127.0.0.1:8080/env.php
*   Trying 127.0.0.1:8080...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET /env.php HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.68.0
> Accept: */*
> : 80
>