使用axios代理槽OpenVPN在VUEJS中受保护的前端

发布于 2025-02-11 09:52:50 字数 883 浏览 1 评论 0原文

希望你们都很好。

我面临着前端实例的问题。 实际上,我们有一个由OpenVPN凭据托管和确保的前端。这意味着,没有与我们的VPN连接的情况下没有人可以访问它。该配置效果很好,但Axios代理仍然存在一个问题。

快速注意:

  • 我们不使用
  • AWS CloudFront
  • Backend托管的服务器端渲染前端部署到AWS EC2实例

中,这是我的Nuxtjs frontend中的当前配置nuxt.nuxt.config.js file> file> file:

{
  ...,

  proxy: {
    '/api/': {
      target: !process.env.FLAVOR
        ? 'http://localhost:8009'
        : (process.env.FLAVOR === 'production'
            ? 'https://api.domain.tld'
            : 'https://' + process.env.FLAVOR + '-api.domain.tld'),
      pathRewrite: { '^/api/': '/v1/' }
    }
  },

  ...
}

此解决方案可帮助我轻松避免所有环境,而无需在Dockerfile中的环境变量以及CORS策略中设置每个URL。

这样,如果我检查控制台Inspector并验证网络选项卡,我将被拒绝,因为未连接到客户端。 VPN和代理如何真正起作用?请求称为客户端还是服务器端?

感谢您的帮助。

hope you are all good.

I'm facing an issue with my frontend instance.
Actually, we have a frontend hosted and secured by OpenVPN credentials. That means, no one can access it without a connection to our VPN. That configuration works well, but still one issue with axios proxies.

Quick notes:

  • we are not using server-side rendering
  • frontend hosted in AWS CloudFront
  • backend deployed to AWS EC2 instances

This is the current configuration in my nuxtjs frontend nuxt.config.js file:

{
  ...,

  proxy: {
    '/api/': {
      target: !process.env.FLAVOR
        ? 'http://localhost:8009'
        : (process.env.FLAVOR === 'production'
            ? 'https://api.domain.tld'
            : 'https://' + process.env.FLAVOR + '-api.domain.tld'),
      pathRewrite: { '^/api/': '/v1/' }
    }
  },

  ...
}

This solution helps me to avoid all environments easily, without setting each URL inside my environment variable in Dockerfile, and also the CORS policy.

In that way, if I check the console inspector and verify the network tab, I got access denied because not connected to the client. How do VPN and proxy really work? Are the requests called client-side or server-side?

Thanks by advance for helping me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文