TransWikia.com

nginx error 500 when making api request to backend container

Server Fault Asked by Christian Geng on November 12, 2021

I am having trouble in setting up a system that consists of an nginx set up as a reverse proxy
processing https requests on a Virtual Machine that is livin on my local computer. This reverse
proxy works with components that are all docker containers generated from a docker-compose.yml.

a) a frontend container including apache that makes request to the backend under www.mymachine.org/api/document/1 to
read a document.
b) a Python api that is a containerized uwsgi application (port 3031)

This is my site configuration:

upstream frontend {
server 127.0.0.1:8080;
}

server {

listen 443 ssl;
listen [::]:443 ssl;

include snippets/self-signed.conf;
include snippets/ssl-params.conf;
server_name mymachine-dev.mydomain.com;

location ^~ / {
  proxy_pass http://frontend/;
 }

location ^~ /api/ {
              uwsgi_pass 127.0.0.1:3031;
              include uwsgi_params;
              # proxy_redirect     off;

              # proxy_set_header   Host              $http_host;
              # proxy_set_header   X-Real-IP         $remote_addr;
              # proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
              # proxy_ssl_server_name on;
              # proxy_set_header Host mymachine-dev.mydomain.com;
              }
}

server {
    listen 80;
    listen [::]:80;
    server_name mymachine-dev.mydomain.com;
    return 302 https://$server_name$request_uri;
}

Symptom: When the frontend makes request to the backend, it results in http 500 – Internal Server errors, similar to that:

XHR GET https://mymachine-dev.mydomain.com/api/documents/1

Status500
Internal Server Error
VersionHTTP/1.1
Transferred391 B (145 B size)

However, I can see from the logs that the requests made by the frontend arrive in the uwsgi container and that it processes the data:

wedaq_frontend_1 | 172.17.0.1 - - [19/Jul/2020:12:43:49 +0000] "GET /documents/1 HTTP/1.0" 200 890
wedaq_frontend_1 | 172.17.0.1 - - [19/Jul/2020:12:43:49 +0000] "GET /css/app.582869e8.css HTTP/1.0" 200 7172
wedaq_frontend_1 | 172.17.0.1 - - [19/Jul/2020:12:43:49 +0000] "GET /css/chunk-vendors.3cb806b4.css HTTP/1.0" 200 251267
uwsgi_1     | Note: entering document generation
uwsgi_1     | [pid: 14|app: 0|req: 3/3] 192.168.178.112 () {52 vars in 1064 bytes} [Sun Jul 19 12:43:49 2020] GET /api/docuements/1 => generated 145 bytes in 6 msecs (HTTP/1.1 500) 5 headers in 154 bytes (1 switches on core 0)
wedaq_frontend_1 | 172.17.0.1 - - [19/Jul/2020:12:43:49 +0000] "GET /js/app.144c2789.js.map HTTP/1.0" 200 426026
wedaq_frontend_1 | 172.17.0.1 - - [19/Jul/2020:12:43:49 +0000] "GET /js/chunk-vendors.f3c2a7c6.js.map HTTP/1.0" 200 4511322

I am having trouble to debug where the mistake actually occurs. My best guess was that I get
something wrong with the certificates – I am using self signed certificates that appear as invalid in the browser window. I have tried replacing the original Ubuntu snakeoil certificates with ones that I generated on my own but the error stays the same.
My question is now whether the ssl issue is able to cause the 500 error and indeed what I should be after, or whether I have to dig into an entirely different region? This is the nginx log complaining about the ssl handshake:

2020/07/19 12:56:39 [info] 3367#3367: *53 SSL_do_handshake() failed (SSL: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown:SSL alert number 46) while SSL handshaking, client: 192.168.178.112, server: 0.0.0.0:443
2020/07/19 12:56:39 [info] 3367#3367: *54 SSL_do_handshake() failed (SSL: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown:SSL alert number 46) while SSL handshaking, client: 192.168.178.112, server: 0.0.0.0:443
2020/07/19 12:56:39 [info] 3367#3367: *58 SSL_do_handshake() failed (SSL: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown:SSL alert number 46) while SSL handshaking, client: 192.168.178.112, server: 0.0.0.0:443
2020/07/19 12:56:39 [warn] 3368#3368: *55 an upstream response is buffered to a temporary file /var/lib/nginx/proxy/1/01/0000000011 while reading upstream, client: 192.168.178.112, server: mymachine-dev.mydomain.com, request: "GET /css/chunk-vendors.3cb806b4.css HTTP/1.1", upstream: "http://127.0.0.1:8080/css/chunk-vendors.3cb806b4.css", host: "mymachine-dev.mydomain.com", referrer: "https://mymachine-dev.mydomain.com/documents/1"
2020/07/19 12:56:39 [warn] 3367#3367: *59 an upstream response is buffered to a temporary file /var/lib/nginx/proxy/2/01/0000000012 while reading upstream, client: 192.168.178.112, server: mymachine-dev.mydomain.com, request: "GET /js/app.144c2789.js.map HTTP/1.1", upstream: "http://127.0.0.1:8080/js/app.144c2789.js.map", host: "mymachine-dev.mydomain.com"
2020/07/19 12:56:39 [warn] 3368#3368: *55 an upstream response is buffered to a temporary file /var/lib/nginx/proxy/3/01/0000000013 while reading upstream, client: 192.168.178.112, server: mymachine-dev.mydomain.com, request: "GET /js/chunk-vendors.f3c2a7c6.js.map HTTP/1.1", upstream: "http://127.0.0.1:8080/js/chunk-vendors.f3c2a7c6.js.map", host: "mymachine-dev.mydomain.com"

Note: I have pursued the warning about the buffering but
an upstream response is buffered to a temporary file
suggests that this is unrelated.

The Response Header looks like this:

    HTTP/1.1 500 Internal Server Error
    Server: nginx/1.14.0 (Ubuntu)
    Date: Tue, 21 Jul 2020 19:40:35 GMT
    Content-Type: text/html
    Content-Length: 145
    Connection: keep-alive
    X-Frame-Options: DENY
    Vary: Origin
    X-Content-Type-Options: nosniff

and this is the content of the response payload:

    <!doctype html>
    <html lang="en">
    <head>
      <title>Server Error (500)</title>
    </head>
    <body>
      <h1>Server Error (500)</h1><p></p>
    </body>
    </html>

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP