为什么PathPrefix不能正常工作,为什么PathPrefixStrip可以工作? [英] Why does PathPrefixStrip work when PathPrefix won't?
问题描述
我有一个使用--prefix-paths
构建的GatsbyJS静态网站. pathPrefix
在gatsby-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:
- 浏览器请求
/environment/test/page
- Traefik将其转换为对
/page
的容器的请求
- 该容器实际上是在
/
上提供文件的,因此它会在页面上答复
- The browser requests
/environment/test/page
- Traefik translates this to a request to the container for
/page
- The container is actually serving files on
/
so it answers with the page
通过Traefik与PathPrefix
连接时:
When connecting via Traefik with the PathPrefix
:
- 浏览器请求
/environment/test/page
- Traefik将其转换为对
/environment/test/page
的容器的请求
- 该容器实际上正在
/
上提供文件,因此找不到该页面.
- The browser requests
/environment/test/page
- Traefik translates this to a request to the container for
/environment/test/page
- 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屋!