openwrt / openwrt/packages

nginx+uwsgi 504 Bad Gateway Time-Out

Open
#23,397 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Makefile
Stars
4.6k
Forks
4k
Avg merge
3d 12h
Merged PRs (30d)
134

Description

Hello, I have encountered the following issue. After several days of testing, I have come to the conclusion and the logs are as follows. I am not sure if it is my setup error or the original Luci ssl nginx bug. Please help me analyze it. Thank you very much.

Maintainer: @<github-user>
Environment: (x86_64, x86_64, LEDE for Lean)

Description:

When I used Docker to pull the image, onlyOffice/documentserver: latest, and downloaded it for 1 minute, I noticed that it
 happened to be 60 seconds, and suddenly returned 504. Then, I switched to uhtpd and did the same operation without this 
problem. I tried to set many parameters for nginx and modify the parameters for uwsgi, but to no avail, I returned an error very
 accurately at 60 seconds. But if I remove smaller images such as nginx, this problem will not occur.
The following are the logs of nginx and logread:

The nginx logs:

2024/02/13 14:48:14 [error] 3132#0: *22 upstream prematurely closed connection while reading response header from upstream, client: 192.168.1.157, server: _lan, request: "POST /cgi-bin/luci/admin/docker/images HTTP/1.1", upstream: "uwsgi://unix:////var/run/luci-webui.socket:", host: "192.168.1.229", referrer: "https://192.168.1.229/cgi-bin/luci/admin/docker/images"

The uwsgi logs

/etc/uwsgi/vassals/luci-webui.ini is ready to accept requests
Tue Feb 13 14:47:23 2024 daemon.err uwsgi[31940]: Tue Feb 13 14:47:23 2024 - [emperor] vassal /etc/uwsgi/vassals/luci-webui.ini is now loyal
Tue Feb 13 14:48:14 2024 daemon.info uwsgi-luci: invalid CGI response !!!
Tue Feb 13 14:48:14 2024 daemon.err dockerd[13056]: time="2024-02-13T06:48:14.918256230Z" level=error msg="Not continuing with pull after error: context canceled"

Run Env

  • LEDE(LEAN) of OpenWRT
  • NGINX: 1.21.3
  • Packege: luci-ssl-nginx uwsgi
nginx configuration
    server_names_hash_bucket_size 512;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
client_max_body_size 8g;

gzip on;
gzip_vary on;
gzip_proxied any;

    fastcgi_connect_timeout 300s;
    fastcgi_send_timeout 300s;
    fastcgi_read_timeout 300s;
    fastcgi_buffer_size 256k;
    fastcgi_buffers 16 256k;
    fastcgi_busy_buffers_size 512k;
    fastcgi_temp_file_write_size 512k;
            fastcgi_intercept_errors on;

root /www;

server { #see uci show 'nginx._lan'
	listen 443 ssl default_server;
	listen [::]:443 ssl default_server;
	server_name _lan;
	include restrict_locally;
	include conf.d/*.locations;
	ssl_certificate /etc/nginx/conf.d/_lan.crt;
	ssl_certificate_key /etc/nginx/conf.d/_lan.key;
	ssl_session_cache shared:SSL:32k;
	ssl_session_timeout 64m;
	access_log off; # logd openwrt;
}

server { #see uci show 'nginx._redirect2ssl'
	listen 80;
	listen [::]:80;
	server_name _redirect2ssl;
	return 302 https://$host$request_uri;
}

location /cgi-bin/luci {
		index  index.html;
		include uwsgi_params;
		uwsgi_param SERVER_ADDR $server_addr;
		uwsgi_modifier1 9;
		uwsgi_read_timeout 1800;
		uwsgi_send_timeout 300;
		proxy_read_timeout 75s;
		proxy_send_timeout 75s;
		proxy_connect_timeout 75s;
		uwsgi_socket_keepalive on;
		uwsgi_force_ranges on;
		uwsgi_connect_timeout 300s;
		uwsgi_ignore_client_abort on;
		uwsgi_next_upstream_timeout 120s;
		uwsgi_next_upstream_tries 10;
		uwsgi_max_temp_file_size 4096m;
		uwsgi_pass unix:////var/run/luci-webui.socket;
}
location ~ /cgi-bin/cgi-(backup|download|upload|exec) {
		include uwsgi_params;
		uwsgi_param SERVER_ADDR $server_addr;
		uwsgi_modifier1 9;
		uwsgi_read_timeout 1800;
		uwsgi_send_timeout 300;
		proxy_read_timeout 75;
		proxy_send_timeout 75s;
		proxy_connect_timeout 75s;
		uwsgi_socket_keepalive on;
		uwsgi_force_ranges on;
		uwsgi_connect_timeout 120s;
		uwsgi_ignore_client_abort on;
		uwsgi_next_upstream_timeout 120s;
		uwsgi_next_upstream_tries 10;
		uwsgi_max_temp_file_size 4096m;
		uwsgi_pass unix:////var/run/luci-cgi_io.socket;
}


location /luci-static {
		error_log stderr crit;
}

location /ubus {
        ubus_interpreter;
        ubus_socket_path /var/run/ubus/ubus.sock;
        ubus_parallel_req 2;
}
Please pay attention to the details. I use a stopwatch to time every 60 seconds, and it returns 504

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided nginx configuration for /cgi-bin/luci and the nginx and uwsgi log entries, then reproduce the Docker image pull that fails after 60 seconds. Compare the nginx/uwsgi path with the reported uhtpd setup. Done means identifying whether the failure is in nginx, uwsgi, or the Luci setup and documenting a confirmed configuration or reproducible bug.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, nginx
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.