ai-traders / liget

NuGet server and cache running on kestrel in docker
MIT License
219 stars 29 forks source link

Running behind reverse proxy #19

Open nivinj opened 5 years ago

nivinj commented 5 years ago

When running LiGet behind a reverse proxy, would be great if there was a way to specify the external URL to LiGet so it can be returned in the responses. In my case, I have LiGet running on internalserver:9011 and I have apache reverse proxying nuget.mycompany.com to internalserver:9011.

However in all the responses from Liget the internal (hidden) URL is used. e.g.: {"version":"3.0.0","resources":[{"@id":"http://internalserver:9011/api/v2/package"...

Ideally should return: {"version":"3.0.0","resources":[{"@id":"http://nuget.mycompany.com/api/v2/package"...

nivinj commented 5 years ago

Probably fixed by accepting an environment variable for proxy endpoint, and using this to build the URL in CarterUrlExtensions.cs https://github.com/ai-traders/liget/blob/e50c365a59a14499fd7cbb233f1533f514fe8c2e/src/LiGet/Extensions/CarterUrlExtensions.cs#L50 https://github.com/ai-traders/liget/blob/e50c365a59a14499fd7cbb233f1533f514fe8c2e/src/LiGet/Extensions/CarterUrlExtensions.cs#L55

viceice commented 5 years ago

@nivinj Im using it behind a traefik proxy, which is working fine. Maybe you have to check the passed HTTP headers

plemanach commented 4 years ago

I passing an env variable to use behind a proxy

docker run -ti -d --env https_proxy=http://myproxy.com

efess commented 4 years ago

If you're using nginx, make sure you're passing the host header as well - since that's what LiGet uses to resolve the absolute URL

proxy_set_header Host            $host;
proxy_set_header X-Forwarded-For $remote_addr;

edit: just a reminder - clear your local nuget http cache if you update this, since nuget will cache the index.json file.

Dunge commented 1 year ago

Anyone know how to do this via a kubernetes ingress-nginx config and route a subpath to the service?

I tried using a generic solution I see in other articles using the rewrite-target annotation to rewrite the url, but the returning xml document doesn't include the sub path.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: http-ingress
  annotations:
    nginx.ingress.kubernetes.io/enable-cors: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  ingressClassName: public
  rules:
  - host: mydomain.com
    http:
      paths:
      - path: /nuget(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: liget
            port:
              number: 9011