Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routing not using proxy path [windows/iis] #1297

Closed
Steven-Harris opened this issue May 2, 2019 · 17 comments · Fixed by #1299 or #2122
Closed

Routing not using proxy path [windows/iis] #1297

Steven-Harris opened this issue May 2, 2019 · 17 comments · Fixed by #1299 or #2122

Comments

@Steven-Harris
Copy link

Steven-Harris commented May 2, 2019

I updated from an alpha version (v4.0.0.0-alpha.2) to the latest beta and my path no longer works. I have https://domain.com/npmregistry. When I navigate to that url it shows the "Sorry, we couldn't find it" page because it's looking for a package named "npmregistry" I can click go home and the application works just fine but the url goes to https://domain.com/. Which is fine until I refresh the page or send someone a direct link. The relative lines of my config are

listen:
  - 0.0.0.0:4873
url_prefix: https://domain.com/npmregistry/
no_proxy: localhost,127.0.0.1

I have the registry host on a computer and proxied from a web server. The npm registry is expose through http://:4873 and then I have an IIS proxy on a web server to allow for access via https://domain.com/npmregistry/

@juanpicado
Copy link
Member

juanpicado commented May 2, 2019

:-) ... I was working on it last night ☺️ ... actually, I know how to fix it, soon I'll post a patch. This repo easily reproduces the bug.

https://github.com/verdaccio/docker-examples/tree/master/reverse_proxy/nginx/relative_path

Thanks for reporting this @Steven-Harris

@juanpicado juanpicado added this to the 4.0.0 milestone May 2, 2019
@juanpicado juanpicado self-assigned this May 2, 2019
@juanpicado
Copy link
Member

@Steven-Harris one question, my fix will remove the url_prefix as you have defined there. It should not be the same something like url_prefix: /npmregistry/ instead?

@Steven-Harris
Copy link
Author

That shouldn't be a problem - I think that's even easier for new users

@juanpicado
Copy link
Member

@Steven-Harris please try with the tag verdaccio/verdaccio:fix-1297 and please verify the issue is being fixed in your side.

@Steven-Harris
Copy link
Author

Gave this a shot and I am getting mixed content/CORS errors. This is due to the fact I am running verdaccio http and the proxy is https. Is there anything I can do to resolve this? beta.5 didn't have this issue.

@juanpicado
Copy link
Member

@Steven-Harris could you show me what exaclty is being affected by CORS?

@Steven-Harris
Copy link
Author

This is what I am getting in the console
image

@juanpicado
Copy link
Member

Do the assets and the page have the same port? I can read different protocol in both ...

@Steven-Harris
Copy link
Author

I just have

listen:
  - 0.0.0.0:4873
url_prefix: /npmregistry/

I am not serving my assets separate from verdaccio api

@Steven-Harris
Copy link
Author

just noticed this in a logs of verdaccio
image

@juanpicado
Copy link
Member

I just have

listen:
  - 0.0.0.0:4873
url_prefix: /npmregistry/

I am not serving my assets separate from verdaccio api

I meant in your reverse proxy configuration.

@Steven-Harris
Copy link
Author

Steven-Harris commented May 6, 2019

oh it's just a simple iis proxy

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <outboundRules>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                </preConditions>
            </outboundRules>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://remote-server:4873/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

@juanpicado
Copy link
Member

Well, I tried with rewrite on my test with nginx and did not work at all. I'm not an expert with this so I make it simpler, this works for me pretty well.

I think if you want to follow such approach http://remote-server:4873/{R:1} you will need to run https within the Docker image.

server {
    listen 8080 default_server;
    access_log /var/log/nginx/verdaccio.log;
    charset utf-8;

    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $host;
      proxy_set_header X-NginX-Proxy true;
      proxy_pass http://verdaccio_v4_root;
      proxy_redirect off;
    }
}

@Steven-Harris
Copy link
Author

Are you suggesting to have verdaccio run https? I happy to play around with it however I am not using docker in this setup just running through npm. beta.5 works perfectly fine with my current setup I am not seeing in the fix branch anything that would cause this

juanpicado added a commit that referenced this issue May 7, 2019
fix: routing is aware of reverse proxy directory #1297
@juanpicado juanpicado reopened this May 7, 2019
juanpicado added a commit to verdaccio/website that referenced this issue May 7, 2019
@juanpicado
Copy link
Member

Are you suggesting to have verdaccio run https?

For some reason, I thought you were using Docker.

I happy to play around with it however I am not using docker in this setup just running through npm. beta.5 works perfectly fine with my current setup I am not seeing in the fix branch anything that would cause this

It would be great if you run some test on your side. The beta.5 allows set complete URL in the url_prefix, but with the new UI (react-router + History API) and the combination sub-directories on reverse proxies, the old approach using URL in the url_prefix create a lot of issues and the #1299 is changing that.

I run a lot of different test in this repo with Docker (https://github.com/verdaccio/docker-examples/tree/master/reverse_proxy/nginx).

Unfortunately, I'm not sure whether the windows setup is still correct (https://verdaccio.org/docs/en/next/iss-server) since I don't use IIS and I have no way to test it.

@juanpicado juanpicado changed the title Routing not using proxy path Routing not using proxy path [windows] May 7, 2019
@juanpicado juanpicado changed the title Routing not using proxy path [windows] Routing not using proxy path [windows/iis] May 7, 2019
@juanpicado juanpicado removed this from the 4.0.0 milestone May 8, 2019
@Steven-Harris
Copy link
Author

@juanpicado I don't think this working as expected. Before the href where being transformed correctly so that they were https://domain.com/registry. but now they are http://localhost:4873/registry. This cause mixed content errors but more over http://localhost:4873/registry doesn't exist. I believe the href should be transformed with the full url the application just needs to be configured so that it is relative to /registry

@juanpicado
Copy link
Member

I'll take of this #2122 please follow up there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants