【问题标题】:Cannot reach the localhost of the server when using ssh port forwarding使用 ssh 端口转发时无法访问服务器的 localhost
【发布时间】:2021-08-14 21:28:44
【问题描述】:

我正在使用 Flask 和 Vue 开发单页应用程序。到目前为止,我一直在笔记本电脑上本地开发和运行 Flask 和 Vue。我现在已经将两者都移到了服务器上,并希望在那里长期运行它们。现在,我保留了原来的“localhost:5000”设置。 Flask 和 Vue 都可以工作,来自 Vue 的 axios-requests 会到达 Flask 应用程序。但是,为了使后者不仅可以在服务器环境上工作,而且可以在我的客户端笔记本电脑上工作,我使用了 ssh 端口转发。现在的实际问题是:我的网站在我的本地浏览器中显示给我,我可以点击,但是 axios-requests 不起作用。这是因为请求试图到达我笔记本电脑的本地主机,而不是服务器的本地主机(当我启动本地 Flask 应用程序时,请求有效)。我确定我只是在这里遗漏了一些重要的东西——我对客户端-服务器架构没有太多经验。

我在 Vue.js 中的一个请求:

methods: {
    getProjects() {
      const path = 'http://localhost:5000/projects';
      axios.get(path)
        .then((res) => {
          this.projects = res.data;
          this.rows = this.projects.length;
          this.setColumns();
        })
        .catch((error) => {
          console.error(error);
        });
    },
...

Flask 应用(服务器端)正在运行:

http://0.0.0.0:5000/

我的 ssh 端口转发:

ssh -o GatewayPorts=true -L 8081:0.0.0.0:8080 me_the_user@the_server

欢迎提出任何建议。

【问题讨论】:

    标签: flask axios bootstrap-vue


    【解决方案1】:

    好的,我现在开始工作了。问题很简单,我只转发了前端/Vue 端口 (8080:0.0.0.0:8080),而没有转发后端/Flask 端口 (5000:0.0.0.0:5000)。

    【讨论】:

      猜你喜欢
      • 2014-07-20
      • 2021-04-15
      • 2016-09-25
      • 1970-01-01
      • 2020-09-30
      • 1970-01-01
      • 2019-01-06
      • 1970-01-01
      • 2017-06-27
      相关资源
      最近更新 更多