Daniel15 / simple-nuget-server

A very simple PHP NuGet server
MIT License
116 stars 43 forks source link

FeedWriter returns invalid download link #10

Open sunsided opened 9 years ago

sunsided commented 9 years ago

This might be part configuration problem on my side and part implementation problem, not sure at the moment. The feed itself runs behind an nginx proxy listening on localhost:80 and rewriting requests to the PHP files; basically the default example configuration.

The nginx runs within a docker container that exposes port 80 as 16473 to the docker host, chosen by a fair dice roll. An apache on the host then in turn listens on port 443, terminates SSL and redirects to the container, as per

ProxyPreserveHost On
<Location /nuget>
    RequestHeader set X-Forwarded-Proto "https"
    ProxyPass http://127.0.0.1:16473
    ProxyPassReverse http://127.0.0.1:16473
</Location>

In this case, requests to

https://my.host.tld/nuget/FindPackagesById()?id='Some.Library'

return

...
<content type="application/zip" src="http://my.host.tld//download/Some.Library/1.3.0-unstable0008"/>
...

which is the wrong protocol (#9) and the wrong path (note the double slash).

Daniel15 commented 9 years ago

The baseURL logic in FeedWriter probably needs some tweaks: https://github.com/Daniel15/simple-nuget-server/blob/master/inc/feedwriter.php#L8-L11

Why do you use Apache at the frontend and Nginx as the origin server? That's a really interesting choice. Why not Nginx for everything, or Nginx as the origin and Varnish or haproxy as the load balancer / SSL terminator?

sunsided commented 9 years ago

I hear you ... sadly the company I'm working with uses Apache for Subversion access, so that's the front-facing server for the time being. In the Docker container, I'm instead using nginx because nginx.

sunsided commented 9 years ago

That said, I just added a patch to the Docker image that simply adds a configurable base URL to all paths in the .conf file. Works as long as the example config doesn't change. :grin:

EDIT: ... except it doesn't work :neutral_face:

Daniel15 commented 9 years ago

Oh yeah, I remember using Apache for subversion many years ago :smile: Apache really isn't too bad.

I can repro the issue with two slashes when running the NuGet server at the root of a domain. The missing path prefix component (/nginx/) is more difficult to fix in a general way, as Nginx doesn't know anything about that path at all (it just sees the http://127.0.0.1:16473/blah path). Does Apache have an option to rewrite URLs in the response? Otherwise you can just have a configurable base URL (like you mentioned you're doing now).

Alternatively you could have it at a subdomain (eg. nuget.my.host.tld), then the paths will match up :laughing:

sunsided commented 9 years ago

Yeah, the subdomain would be my favorite, but sadly that's no option at the moment due to the SSL certificate; I'm basically restricted to a shared "development" subdomain.

On the Apache side, I could imagine passing in the base URL as a X-NuGet-Base header or something. At the moment I'm getting a friendly 404 on the /nuget/download/... route with my naive patching approach (which is this one). (that's fixed)