私有 NuGet 服务器:请求实体过大

18
我们有一个内部的NuGet服务器(使用NuGet.Server包的ASP.net应用程序),我们希望与Octopus一起使用它来部署软件包。首先需要注意的是软件包太大了。 当您推送大于约7兆的软件包时,会出现以下错误: 无法处理请求。'请求实体过大'。远程服务器返回了一个错误:(413) 请求实体过大.. 根据Octopus的文档,我更新了web.config文件进行更改。
<?xml version="1.0" encoding="utf-8"?>

<configuration>
    <configSections>
        <sectionGroup name="elmah">
            <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/>
            <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah"/>
            <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah"/>
            <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/>
        </sectionGroup>
    </configSections>
    <system.web>
        <compilation debug="true" targetFramework="4.0"/>
        <httpModules>
            <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
            <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
            <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
        </httpModules>
        <httpRuntime maxRequestLength="419430400" executionTimeout="3600"/>
    </system.web>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules runAllManagedModulesForAllRequests="true">
            <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler"/>
            <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler"/>
            <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler"/>
        </modules>
        <staticContent>
            <mimeMap fileExtension=".nupkg" mimeType="application/zip"/>
        </staticContent>
        <security>
            <requestFiltering>
                <requestLimits maxAllowedContentLength="419430400"/>
            </requestFiltering>
        </security>
    </system.webServer>
    <elmah>
        <security allowRemoteAccess="false"/>
        <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data"/>
    </elmah>
    <location path="elmah.axd" inheritInChildApplications="false">
        <system.web>
            <httpHandlers>
                <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
            </httpHandlers>
        </system.web>
        <system.webServer>
            <handlers>
                <add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode"/>
            </handlers>
        </system.webServer>
    </location>
    <appSettings>
        <add key="apiKey" value="KeyHere"/>
        <add key="packagesPath" value=""/>
    </appSettings>
    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    </system.serviceModel>
</configuration>

这并没有起作用。其他帖子中提到需要运行如下命令(对于IIS7):

appcmd.exe set config -section:system.webServer/serverRuntime /uploadReadAheadSize:"419430400" /commit:apphost

或者(对于IIS6):

cscript adsutil.vbs set w3svc/1/uploadreadaheadsize 419430400

我已经尝试了两种方法,但都没有成功。由于没有返回任何错误信息,我认为对于所有的调用,“419430400”这个值是正确的(以字节为单位而非其他大小单位)。

有人知道我漏掉了什么吗?

最终,我只好将包复制到Web服务器上的共享目录中,但我真的很想使“push”命令起作用。


我也按照@Tyrel的步骤做了同样的事情,并且手动将包放入文件夹中。我希望我的构建服务器能够将软件包推送到另一台机器上的NuGet服务器。至今我还没有看到这个问题的明确答案。 - Mike G
8个回答

35

并没有完全回答楼主的问题,但是与这个话题相关。我在使用 NuGet push 推送到本地 SymbolSource 服务器时遇到了 (413) Request Entity Too Large 错误 - 后来发现我提交的 URL 稍微有点不正确,一旦将命令修正为指向基础的 /NuGet/ URL,它就可以顺利运行。

不知道为什么一个错误的 URL 会导致 413 错误,但是就是这样。希望能对某人有所帮助。

编辑:根据下面的评论,你可能更幸运,只需要引用基础的 http://www.myserver.com/ URL 而不需要包含 /NuGet。值得尝试一下。


帮了我大忙!我也因为错误的URL遇到了这个问题。谢谢! - Matt M
9
针对我的情况,我需要删除 /NuGet 路径并仅保留基本的URL:http://localhost:56211 - stack247
像 stack247 一样,只有当我删除末尾的 nuget/ 部分时才能正常工作,因此它应该是这样的:http://nuget.internalserver.com/NuGetServer/ 而不是 http://nuget.internalserver.com/NuGetServer/nuget。 - Ben Humphrey
这真的很麻烦,因为Visual Studio(至少是2013版)需要使用/nuget后缀。这使得使用nuget.exe并在-source参数中使用配置的别名变得困难/不可能(例如'teamcity'而不是'http://myteamcityserver:someport/some/other/guff')。 - piers7
啊,终于解决了。列表/恢复和推送之间所需的URL不一致,这是所有混淆的根源。请参见下面的答案。 - piers7

7

我知道这是一个老问题,但今天我也遇到了相同的错误。值得注意的是,我正在使用 TeamCity 进行包的构建和发布。无论如何,当我尝试发布我的大型包(约 200 MB)时,出现了阻塞情况。解决方案很简单:

不要发布到 http://mynugetserver/api/v2/而是使用:http://mynugetserver/


2

2

您需要将以下两个值设置为更高的值:

  • system.web - httpRuntime - maxRequestLength,例如1048576
  • system.webserver - security - requestFiltering - requestLimits - maxAllowedContentLength,例如1073741824

这两个值使用不同的单位,因此第二个值应该比第一个值大。

此外,当使用Octopus Deploy时,建议访问www.myget.org网站以获取更多帮助。


Tyrel已经在httpRuntime上将maxRequestLength设置为419430400。那应该远远足够了。但我使用一个大小为120KB的程序包仍然遇到同样的错误。 - Mike G

2
请检查您的serverRuntime配置。 maxRequestEntityAlloweduploadReadAheadSize属性分别配置请求实体主体中允许的最大字节数以及Web服务器将读取到缓冲区并传递给ISAPI扩展的字节数的限制。
更多细节请参考:http://www.iis.net/configreference/system.webserver/serverruntime 我的猜测是您正在使用SSL,设置uploadReadAheadSize将解决此问题。因为在客户端重新协商过程中,必须使用SSL预加载请求实体主体。SSL预加载将使用uploadReadAheadSize属性的值,该值用于ISAPI扩展。
以下是默认值:
<location path="Default Web Site"> 
   <system.webServer> 
      <serverRuntime enabled="true" 
         uploadReadAheadSize="49152" 
         maxRequestEntityAllowed="4294967295" /> 
   </system.webServer> 
</location>

0

这是由于nginx的限制,Linux系统中的NuGet服务器使用nginx作为代理,并在以下位置配置文件:

/etc/nginx/conf.d/nuget.conf

server_name localhost;
root /var/www/public/;
client_max_body_size 200M;

将 client_max_body_size 改为 200M 对我有效。


0

我遇到了同样的问题:

[Step 1/2] Publishing package to feed at http://localhost/OctopusDeploy/nuget/packages...
[Step 1/2] Failed to push to package feed at 'http://localhost/OctopusDeploy/nuget/packages/'. 
[Step 1/2] (The server responded with: [413] Request Entity Too Large)
[Step 1/2] Process exited with code 1

但是Octopus Deploy服务已经停止了!


-1

1
在推送包时,您不需要在URL末尾添加/nuget。但是在检索它们(例如nuget列表)时需要添加。这在文档中有说明,但是...天哪,这样会让每个人都感到困惑。 - piers7

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接