【问题标题】:Proxy Error 502 on Apache2 for Reverse Proxy to NodeJs Subdomain App on Digital OceanApache2 上的代理错误 502,用于反向代理到 Digital Ocean 上的 NodeJs 子域应用程序
【发布时间】:2020-03-18 10:56:59
【问题描述】:

大家好

我试图在 Digital Ocean 上部署我的 nodejs api,在子域 https://api.host.com 下。它有一些路径波纹管,都从 /v0.1 开始。

例如https://api.host.com/v0.1/users

在这个 droplet 上,nodejs 应用程序正在 http://localhost:3000 上运行

在同一个 droplet 上,我有其他应用程序,一个托管在 Apache 上的网站,并在 https://host.com 回复它工作正常。

我使用 Apache 进行反向代理,从 https://api.host.com/http://localhost:3000 进行所有调用。

实际上它只适用于根路径,我的意思是尝试访问https://api.host.com/ 响应正确但是当我尝试访问其他路径时出现错误

Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request

Reason: DNS lookup failure for: 127.0.0.1:3000v0.1

Apache/2.4.29 (Ubuntu) Server at api.host.com Port 443

HTTP 状态码:502 代理错误

我的虚拟主机看起来像...

<VirtualHost *:80> 
        ...
        ...
        ServerName api.host.com 
        ProxyPass /.well-unknown/ !
        ProxyRequests Off
        ProxyPreserveHost On
        ProxyVia Full
       <Proxy *>
          Require all granted
      </Proxy>

      ProxyPass / http://127.0.0.1:3000/ 
      ProxyPassReverse / http://127.0.0.1:3000/ 
      ...
      ...
 </VirtualHost>

请帮忙!

【问题讨论】:

    标签: node.js apache reverse-proxy


    【解决方案1】:

    我正在使用 Apache 服务器将请求从子域通过代理转发到我在端口 8080 上侦听的 nodeJS 应用程序做同样的事情。

    我相信你只需要代理传递根到 localhost:3000 并且 nodeJS 应用程序应该处理路由。

    例如,如果您使用的是 express,则类似于.....

    app.get('/v.01/users/', function (req, res) {
       res.sendFile('/v.01/users/index.html'); });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-03
      • 2017-01-23
      • 2021-12-27
      • 2021-12-18
      • 1970-01-01
      • 1970-01-01
      • 2014-01-07
      相关资源
      最近更新 更多