Nuget feed behind IIS reverse proxy not working



I am using IIS as a reverse proxy. It is working as expected except for the Nuget feed. The <Content> element for the package url is still showing as localhost:8080 instead of the public host. Does anyone know how to fix this?

I also have the following error on the Nuget settings page.

"NuGet Feed must contain server URL inside. Current TeamCity server configuration does not let TeamCity server to get original request URL from HTTP request. It looks like TeamCity server is wrongly configured with reverse proxy. Make sure reverse proxy and TeamCity server is configured to let TeamCity server know request real request URL"

The feed used to work correctly. I think it broke on the upgrade from version 7 to 8 (currently running 8.02).

My web.config rewrite rule is as follows

<rule name="ReverseProxy-teamcity" stopProcessing="true">
    <match url="(.*)"/>
    <action logRewrittenUrl="true" type="Rewrite" url="http://localhost:8080/{R:1}"/>
        <add input="{HTTP_HOST}" pattern="teamcity.svr-it"/>
        <set name="HTTP_ACCEPT_ENCODING" value=""/>
        <set name="HTTP_X_FORWARDED_HOST" value="teamcity.svr-it"/>
        <set name="HTTP_X_FORWARDED_SERVER" value="teamcity.svr-it"/>
        <set name="HTTP_HOST" value="teamcity.svr-it"/>
        <set name="SERVER_NAME" value="teamcity.svr-it"/>

The Teamcity Server URL is set to http://teamcity.svr-it

Any ideas to fix this would be appreciated, thanks.

Comment actions Permalink

I found this issue in the bugtracker that includes a workaround for the problem

I assume this was already in place and the update reset the server.xml file

Comment actions Permalink

I wasn't able to force TeamCity to respect request header (X-Forwarded-Proto) set by reverse proxy when generating nuget feed urls. It should work like this according to a few posts from JetBrains I found online but it doesn't in my case. Reverse proxy uses https but TeamCity instance works over http. Even though TeamCity is aware of the reverse proxy in front of it (everything else works), nuget feed still has http links inside causing Visual Studio to fail when installing from it.

Instead of relying on TeamCity to generate proper urls in nuget feed, I have added an outbound rule to reverse proxy (IIS) to convert all http addresses in response body to https. Online documentation of ARR shows only how to manipulate HTML tags in response body, but nuget response has XML format. So in order manipulate XML response the trick is not to select anything in Match the content within combo box. If you don't select anything, the rewrite will take whole response body as input, not limiting us to HTML tags.


Please sign in to leave a comment.