Netlify nginx config

Hi,

im getting CORS errors when uploading images larger than 2 MB on my netlify free tier hosted website (server is on another domain). Im assuming this is due to the 2 MB nginx file size limit in the default nginx config. Is there any way around this?

Cheers

So, you’re using your Netlify website to upload files to a nginx server? Well, if that’s true, you need to configure that server, specifically to allow CORS, you need to add he headers. Read here: How to Enable CORS in Apache and Nginx?

My server is configured to allow CORS, everything works fine (REST calls etc) also uploading images below 2 MB works fine, its just when they are larger than 2 MB.

Edit: my server (express) is also configured to allow file uploads up to 50 MB

This still seems to be an issue with the nginx server. Please correct me if I’m wrong. I am not sure we can specifically pinpoint as to what needs to be done.

Yes, im assuming that when you use a netlify site, it spins up an nginx in the background. Can i access these netlify nginx settings somewhere?

No, Netlify doesn’t spin up any nginx server, at least I’ve never heard anything like that. Could you explain how you were led to that assumption?

Well, netlify needs some kind of web server to serve the static files i deploy, right? I dont know what web server they use, nginx was an assumption :slight_smile:

Sure, that’s a possibility. However, there’s no configuration that you can change. You can only specify redirects and headers, but that’s not going to help you.

If I may ask, how are you uploading the files, or if there’s somewhere we can test this live?

I can give you access but i wouldnt want anyone to use it, does this forum have a DM feature?

Yes, you can go on my profile and send me a DM.

Or if possible, you can fire up a test repo or something which can have the same issue, so you can keep your actual stuff secret.

I did that and as you said, I got the error while uploading a 4 MB image. However, I am getting the same error while uploading a 1.06 MB image too.

Also, I don’t see any CORS headers on the URL:

image

Just to confirm, are you sure they’re configured correctly?

the process.env.FRONTEND_URL is the one you are on right now. If that wasnt configured properly, nothing would work

Regarding the file sizes: Maybe its not 2MB but 1MB? Anything under 1 MB works, e.g. this file

Also, as you see the response is from nginx. I dont use an nginx on my backend or somewhere else. The nginx is 100% from netlify

Hold up! I am immensily stupid!

I figured it out. I AM actually using an NGINX which was misconfigured, i just didnt notice it. Im hosting my server via dokku which spins up an nginx by default in the background. That nginx had a max file size of ~2 MB. i managed to change the settings and now it works. Sorry for thinking this was netlifys fault!

Edit: Should anyone stumble across this post for some reason, this dokku plugin makes it super easy to change the dokku nginx max file size GitHub - Zeilenwerk/dokku-nginx-max-upload-size

1 Like

Thanks @hrishikesh for helping me out on this one <3

1 Like

Glad you figured this out. It’s almost the same thing I was typing.

2 Likes