nginx reverse proxy and NextCloud

wireframed

Ars Legatus Legionis
17,367
Subscriptor
Hi guys - not sure if this is entirely the correct sub-forum but here goes. :)

I'm ripping my hair out over a NextCloud issue that I *think* is related to my nginx reverse proxy setup, but not at all sure. (NextCloud is a fork of OwnCloud if you guys are familiar).

Problem Outline
The general issue is, I can only upload 10MB to NextCloud before it just stops. It may trickle a few kb through, but I'm not sure it even does that. If I disable proxy_buffering, I can't even upload that, so my assumption is the buffer is written, but then something fails when writing the the NextCloud instance in the VM.

I think the NextCloud instance itself works, because if I access it directly via the LAN IP (10.0.0.6), it works fine. I can upload files at max line speed and everything is fine. Via HTTPS not at all fine...

System Config, Short Version
- I've set up a NextCloud instance on a server at my home office, using the official Linux VM image. The VM is running in VMWare Pro as a shared VM and it seems to work fine. It has a fixed IP on the local network.
- I'm running latest RC of NextCloud.
- I've set up nginx as a general reverse proxy to access various services on the server, among these NextCloud. The traffic is sent to the fixed IP with "proxy_pass https://10.0.0.6;".
- I'm running nginx 1.19.6
- I've also set up a certificate for SSL for the subdomain NextCloud is running on. (nextcloud.MYDOMAIN.com). These seem to check out fine.
- Other services running via nginx or proxied by it seem to work fine.
- Everywhere I can set a client body size, it has been set to a generous/overkill value (10000m), and timeouts are generally above 3600 seconds. Even files that are 20-30MB will fail. This is both in NextCloud Apache config and nginx config on the proxy.
- The server hardware is plenty sufficient.
- The internet speed is 500/500.

Logs
nginx has some WARNs: "a client request body is buffered to a temporary file C:\Webserver\nginx/temp/client_body_temp/0000000800," repeatedly.
NextCloud shows: "Sabre\DAV\Exception\BadRequest: Expected filesize of 10000000 bytes but read (from Nextcloud client) and wrote (to Nextcloud storage) 1171456 bytes. Could either be a network problem on the sending side or a problem writing to the storage on the server side."
NextCloud also shows: "Error: fread(): file created in the system's temporary directory at /var/www/nextcloud/apps/files_external/3rdparty/icewind/streams/src/Wrapper.php#91"

There are a lot of suggestions on fixing this, but all I've tried have failed. Mostly they dealt with the client body size being low, or the connection timing out mid-transfer. That is not the case here, I think.

Any help would be much appreciated. I can upload appropriate logs if necessary. :)
 

w00key

Ars Legatus Legionis
10,103
Subscriptor
Maybe try http://nginx.org/en/docs/http/ngx_http_ ... _buffering
That way, it doesn't buffer the body before sending it to PHP.


But I would also check the config for a stray 10000000 / 10M in the config. Maybe you accidentally set the content length header? What version of Nginx are you running?

[edit]
Wait, it doesn't upload at all with proxy_buffering? That's just plain weird. Can you post config files sanitized for hostname/usernames?
 

wireframed

Ars Legatus Legionis
17,367
Subscriptor
Hey w00key, thanks for your reply.

Actually, it seems now it still uploads 10MB before halting with proxy buffering off - previously it didn't, but I've futzed a lot with the config.

Here's the nginx config (It's 1.19.6). I've removed all the server configs that should be relevant here, so only the nextcloud configs and general setup is preserved:

Code:
#user  nobody;
worker_processes  12;

error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;
error_log  logs/error.log  crit;
#error_log  logs/debug.log  debug;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       	mime.types;
    default_type  	application/octet-stream;
	server_names_hash_bucket_size  64;
	access_log  	logs/access.log;

    sendfile        	on;
    keepalive_timeout 	3600;
    
	
	# COMPRESSION
	gzip on;
	gzip_comp_level 2;
	gzip_min_length 1000;
	gzip_types text/plain application/x-javascript text/xml text/css application/xml;
	
	server {
		listen       	80;
		server_name 	nextcloud.MYDOMAIN.com;

		return 301 https://$host$request_uri;

        location / {
        }
    }
	
	server {
		server_name  	nextcloud.MYDOMAIN.com;
		listen		 	443 ssl;
				
				
		set $upstream 10.0.0.6;
		
		
		# SSL CONFIGS
		ssl_session_timeout 			1d;
        ssl_session_cache 				shared:SSL:100m;
        ssl_session_tickets 			off;
        ssl_protocols 					TLSv1.1 TLSv1.2;	
		ssl_certificate 				"c:/Certbot/live/nextcloud.MYDOMAIN.com/fullchain.pem";
		ssl_certificate_key 			"c:/Certbot/live/nextcloud.MYDOMAIN.com/privkey.pem";
		ssl_ciphers 					'CYPHER_STRING_HERE';
        ssl_prefer_server_ciphers 		on;

		
        # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
        add_header Strict-Transport-Security max-age=15768000;
		
		
        location / {
			proxy_pass_header 			Authorization;
			proxy_pass 					https://$upstream;
			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_http_version 			1.1;
			proxy_set_header 			Connection 			"";
			proxy_buffering 			off;
			client_max_body_size 		0;
			proxy_read_timeout 			36000s;
			proxy_redirect 				off;
			proxy_ssl_session_reuse 	off;
		}
	}
	
	client_max_body_size 1000m;
}

I can post my NextCloud config as well. AFAIK I only need to change client body size in Apache and the php.ini on the NextCloud side? I did just notice that strangely PHP filesize flashes from 512MB to 2MB when reloading - previously it read 1GB which I had set in the config. It's difficult to find definitively where to set the upload filesize. :-/ I don't think I have 10MB anywhere though (10M)...

:edit: The last part is my fault - I deleted a "'" in php.ini, so the config wasn't loaded correctly. After fixing my max upload size is again 10G, but the issue persists.

L.
 

w00key

Ars Legatus Legionis
10,103
Subscriptor
Wait you go Nginx - Apache - PHP?


Have you considered running PHP via PHP FPM?

Nginx part: https://www.nginx.com/resources/wiki/st ... s/phpfcgi/
PHP part: basically apt install https://packages.ubuntu.com/focal/php/php-fpm


We have been running this in prod since forever, works much better than mod_php in Apache.

I am guessing something within Apache is wonky, there is nothing wrong with here.
 

wireframed

Ars Legatus Legionis
17,367
Subscriptor
Wait you go Nginx - Apache - PHP?


Have you considered running PHP via PHP FPM?

Nginx part: https://www.nginx.com/resources/wiki/st ... s/phpfcgi/
PHP part: basically apt install https://packages.ubuntu.com/focal/php/php-fpm


We have been running this in prod since forever, works much better than mod_php in Apache.

I am guessing something within Apache is wonky, there is nothing wrong with here.
Sorry for the confusion. I'm running the standard NextCloud VM as my server is a Windows server. So it already uses PHP FPM in the VM.
I then use nginx running natively in Windows to work as a reverse proxy to both services and the VM that runs Nextcloud.

So it's really just:
nginx proxy -> NextCloud VM

As the NextCLoud VM is relatively standard, excepting I've changed the post size values to 10G where I found them, I suspect nginx is the culprit. Especially as direct connections to 10.0.0.6 (VM IP) works just fine.

L.
 

wireframed

Ars Legatus Legionis
17,367
Subscriptor
Just to rule out any issues with all the futzing I've been doing, I tried downloading and setting up the VM from the base again, and same issue. So it would seem the nginx setup (or some other factor in my networking setup) is causing the issue.

Any ideas how to troubleshoot this? I'm not really that experienced in networking, but nginx works fine for my other purposes, and the logs I'm looking into don't really point at any root cause I can identify. :-/

L.
 

w00key

Ars Legatus Legionis
10,103
Subscriptor
I guess you need the port 80/443 on Windows because you DMZ everything to it right?

Running servers (Nginx, Apache, etc) stuff on Windows is a bit iffy, if it works it works, but googling for solutions when it breaks is hard...

What happens if you DMZ to a Linux VM with basically the same Nginx config, and from there on, proxy_pass it to the NextCloud VM?
 

wireframed

Ars Legatus Legionis
17,367
Subscriptor
I guess you need the port 80/443 on Windows because you DMZ everything to it right?

Running servers (Nginx, Apache, etc) stuff on Windows is a bit iffy, if it works it works, but googling for solutions when it breaks is hard...

What happens if you DMZ to a Linux VM with basically the same Nginx config, and from there on, proxy_pass it to the NextCloud VM?
Not DMZ, but port 443 and port 80 are forwarded to my server yes. Short version, I run a lot of services (Plex, rendering, file server, backups, a few sites etc) and I’m much more at home with Windows, aside from it being better supported for rendering and Plex. So the server runs Windows but NextCloud only supports Linux, so I run that in a VM. Hence the setup with an nginx server on Windows forwarding traffic to a VM. :)

Setting up a Linux VM with nginx on a Windows server, forwarding to NextCloud VM (and also all the other services that have reverse proxies,,,) seems pretty complicated and I’m not sure the basic issue wouldn’t remain. Not being able to upload to the VM seems like a more basic config issue, and copying the confit to Linux strikes me as unlikely to solve the issue? Surely if nginx in Windows couldn’t pass traffic via proxy, someone would have mentioned it? :)

It’s evening here, tomorrow I’ll sketch up a network diagram of the setup - maybe something is set up wrong that isn’t clear from my description. :)

L.