为什么PathPrefix不能正常工作,为什么PathPrefixStrip可以工作? [英] Why does PathPrefixStrip work when PathPrefix won't?

查看:345
本文介绍了为什么PathPrefix不能正常工作,为什么PathPrefixStrip可以工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用--prefix-paths构建的GatsbyJS静态网站. pathPrefixgatsby-config.js中设置为/environment/test.它被部署到运行Traefik的Docker集群中.

I have a GatsbyJS static site built with --prefix-paths. The pathPrefix is set to /environment/test in gatsby-config.js. It is deployed to a docker swarm running Traefik.

在服务中添加以下标签可使一切正常运行: traefik.frontend.rule=PathPrefixStrip:/environment/test

Adding the following label to the service makes everything run ok: traefik.frontend.rule=PathPrefixStrip:/environment/test

然后我可以浏览到/environment/test并在我的GatsbyJs网站中单击.

I can then browse to /environment/test and click around in my GatsbyJs site.

但是我发现这很奇怪,因为后端是使用路径前缀构建的.

However I find it strange since the backend is build with the path prefix.

添加以下标签无效: traefik.frontend.rule=PathPrefix:/environment/test

Adding the following label does not work: traefik.frontend.rule=PathPrefix:/environment/test

它不能与PathPrefix一起使用而不是PathPrefixStrip吗?

Shouldn't it work with PathPrefix instead of PathPrefixStrip?

推荐答案

GatsbyJS中的pathPrefix配置意味着您网站的每个链接都将以/environment/test开头(请参见

The pathPrefix configuration in GatsbyJS means that every link of your website will be prepended with /environment/test (see documentation), but this does not mean that on the container running the website, the page is actually hosted on this path. In your situation, it seems it is not the case.

这意味着当通过Traefik与PathPrefixStrip连接时,在浏览器中单击链接:

This means that when connecting via Traefik with the PathPrefixStrip, when in your browser you click on a link:

  1. 浏览器请求/environment/test/page
  2. Traefik将其转换为对/page
  3. 的容器的请求
  4. 该容器实际上是在/上提供文件的,因此它会在页面上答复
  1. The browser requests /environment/test/page
  2. Traefik translates this to a request to the container for /page
  3. The container is actually serving files on / so it answers with the page

通过Traefik与PathPrefix连接时:

When connecting via Traefik with the PathPrefix:

  1. 浏览器请求/environment/test/page
  2. Traefik将其转换为对/environment/test/page
  3. 的容器的请求
  4. 该容器实际上正在/上提供文件,因此找不到该页面.
  1. The browser requests /environment/test/page
  2. Traefik translates this to a request to the container for /environment/test/page
  3. The container is actually serving files on / so it doesn't find the page.

因此,您将网站的pathPrefix设置与提供相同网站的路径混淆了.

Hence, you are confusing the pathPrefix setting of a website with the path from which the very same website is served.

因此,替代当前情况的方法是在/environment/test/下提供网站服务,并在traefik中使用PathPrefix.

The alternative to the current situation would thus be to serve the website under /environment/test/ and use PathPrefix with traefik.

这篇关于为什么PathPrefix不能正常工作,为什么PathPrefixStrip可以工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆