首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VueJS :反向代理背后的相对资源不起作用

VueJS :反向代理背后的相对资源不起作用
EN

Stack Overflow用户
提问于 2019-10-31 14:38:11
回答 1查看 928关注 0票数 1

简介

我在反向代理(traefik 2.0)后面为所有类型的容器(docker)服务,比如后端应用程序(nodejs)或前端应用程序(vuejs)。实际上,我试图在像https://localhost/my-app这样的路径后面服务一个https://localhost/my-app

我所期望的

container

  • VueJS应用程序
  • Traefik将/my-app重定向到vuejs
  • 应用程序,
  • VueJS应用程序通过<link href=css/app.css>.

等相对路径加载资源。

我所拥有的

  • VueJS应用程序不能正常工作,因为无法正确获取资源。浏览器后面的
    • ( VueJS根页面)正在尝试获取https://localhost/css/app.css上的相对资源,而不是https://localhost/my-app/css/app.css,您知道如何使用/my-app重定向

    后面的相对资源为VueJS提供服务吗?

配置文件

请参阅下面的配置文件。

docker-compose.yml

代码语言:javascript
复制
version: "3.7"

services:
  vuejs:
    restart: always
    build:
      context: .
      dockerfile: ./Dockerfile
    image: my-vuejs-app:latest
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.my-app-router.rule=PathPrefix(`/my-app`)"
      - "traefik.http.routers.my-app-router.tls=true"
      - "traefik.http.middlewares.path-strip.stripprefixregex.regex=^/[a-zA-Z0-9_.-]+"
      - "traefik.http.routers.my-app-router.middlewares=path-strip@docker"

vue.config.js

代码语言:javascript
复制
module.exports = {
  publicPath: './'
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-04 09:02:19

我使用了一个中间件,它在请求的末尾添加了一个/。这样,就可以按预期的方式加载相关资源。

示例:(我的码头服务中的Traefik标签)

代码语言:javascript
复制
- "traefik.enable=true"
- "traefik.http.routers.my-app-router.tls=true"
- "traefik.http.routers.my-app-router.rule=PathPrefix(`/my-app`)"
- "traefik.http.middlewares.test-redirectregex.redirectregex.regex=^(https|http)://([a-zA-Z0-9_.-]+)/([a-zA-Z0-9_.-]+)$$"
- "traefik.http.middlewares.test-redirectregex.redirectregex.replacement=$${1}://$${2}/$${3}/"
- "traefik.http.routers.my-app-router.middlewares=test-redirectregex@docker,path-strip@file"
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58645726

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档