Private NuGet server behind nginx (Request Entity Too Large)

Spent some time today trying to make NuGet.Server work so that I can host my own packages. I’m working on a new .NET core project on my Mac and wanted to host the server in IIS which is accessible from various machines. 

I’ve got a public facing web server running nginx which is connected to a windows server behind it (actually via VPN). I use nginx proxy_pass feature to pass the request on backwards to the IIS server. 

I was trying to push a package to the server and got this error:

PUT http://nuget.XXXXXXX/api/v2/package/

An error was encountered when fetching ‘PUT http://nuget.XXXXXXX/api/v2/package/’. The request will now be retried.

Request Entity Too Large

In other cases I just got this:

PUT http://nuget.XXXXXX

An error was encountered when fetching ‘PUT http://nuget.XXXXXX/’. The request will now be retried.

Cannot access a disposed object.

Object name: ‘System.Net.Sockets.NetworkStream’.

(I don’t really know why I seemed to get 2 different errors – I didn’t do much digging). 

The cause of this issue was that nginx was limiting the max body size request to 1M and it seems to inspect Content-Length header before receiving the full request. If it exceeds 1M, it returns a 413 error. See client_max_body_size for more info. 

The fix is simple. In my case, on my Linux server I opened /etc/nginx/nginx.conf and appended this line:

client_max_body_size 10M;

This needed to be append inside the http {} block.

Restart nginx and push again. 

Hope this helps someone.



Leave a Reply

Your email address will not be published. Required fields are marked *