NextCloud + CDN

Hi Guys,

We are using V 9.0.53 + NGINX + CloudFront. Unfortunately, it seems WebDAV (NextCloud) is failing if run through the CDN - the error is “This operation is forbidden”. Is there any way to have the script populate files without WebDAV? I presume the CDN is blocking the ports and it would be nice to have everything accelerated versus running directly…

No errors in nginx or nextcloud logs. Works fine if we remove the CDN and access directly.

Thanks.

Bump. Hopefully someone knows a way around this to get NextCloud to work? Reviewing previous talk it seems to display the files in one’s browser NextCloud uses webdav…

As only static files are accelerated by a CDN and all dynamic stuff most likely is slowed down due to an extra network hop, rewriting nginx delivered files to replace static file assets to the CDN equivalent should do the trick.

You can check out: http://nginx.org/en/docs/http/ngx_http_sub_module.html

It enables the rewriting of urls inside the responses. If you have a working nginx config, I’d love to see that.

1 Like

I am using the following configuration:

sub_filter_once off;
sub_filter 'defer src="/core/' 'defer src="https://cdn.example.com/core/';
sub_filter 'defer src="/apps/' 'defer src="https://cdn.example.com/apps/';
sub_filter '<link rel="stylesheet" href="/apps/' '<link rel="stylesheet" href="https://cdn.example.com/apps/';
sub_filter '<link rel="stylesheet" href="/core/' '<link rel="stylesheet" href="https://cdn.example.com/core/';

Since I have set it up just a short while ago, I can’t tell whether you’ll run into any troubles replacing like that, but I suppose that it should work out. Just make sure to add your CSP to include cdn.example.com as a style-src and you should be set.

@kasim where exactly did you insert that? I’ve tried it but URIs are not rewrited after nginx reload…thanks :slight_smile:

Hey @bloo, sorry for late response. Here’s my setting:

Nextcloud is running on an Apache server, in front of that is an nginx reverse proxy. The above config is inserted into the nginx config for location /.

Be warned that using the above settings might not be wise unless your CDN always has access to the up to date data on your main server. Otherwise, changes to apps and settings, etc. may not work properly.

P.S.: I had tested this with Nextcloud 19. I’m not sure if any changes were made with version 20 for this to not work properly. So do it at your own risk.