Possible to use a CDN like BunnyCDN?

Currently running Gitea 1.8.2, wondering if it is possible to use a CDN like BunnyCDN for files such as CSS and JS? My instance is hosted in Germany, while I am in Brazil, so I would love to reduce latency as much as possible.

CloudFlare is not an option right now. I believe I already know the answer, but I figured asking would not hurt.

Thanks in advance!

Yes it is possible, but you would need to set SSH_DOMAIN to a non-CDN URL that resolves directly to the server. More details on that option: https://docs.gitea.io/en-us/config-cheat-sheet/

I might be missing something, but I do not see a setting to change URL for static files on that page. Would I need to change ROOT_URL to match the CDN?

You’d need to put the entire site behind the CDN, by changing ROOT_URL (as you found out already), and then all SSH traffic would be handled by a different domain.

Hm, not what I hoping for, but maybe I can make it work with NGINX, try_files and proxy_pass instead.

Thanks for looking into this, @techknowlogick!

I think you mean only static resources for CDN since dynamic content is not suitable for generic CDN. I have sent a PR https://github.com/go-gitea/gitea/pull/6341 to try to resolve this, but not finished yet.

@lunny That is exactly what I was looking for, thanks! I will try to make it work with NGINX for now — and write about it if I can make it work.

Okay, I got it working using the ngx_pagespeed module with NGINX. I will write about it later this week, but to make things simple, the following settings inside server {} should get it working.

pagespeed EnableFilters rewrite_domains;
pagespeed Domain https://YOUR-DOMAIN;
pagespeed MapRewriteDomain https://cdn.YOUR-DOMAIN https://YOUR-DOMAIN;
1 Like