Apache2 上的代理错误 502 反向代理到 Digital Ocean 上的 NodeJs 子域应用程序



大家好

我试图在子域 https://api.host.com 下的数字海洋上部署我的nodejs api。它有一些路径,全部从/v0.1 开始。

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

在这个快捷批处理上,nodejs 应用程序运行在 http://localhost:3000

在同一滴中,我得到了其他应用程序,一个托管在 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>

请帮忙!

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

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

例如,如果您使用的是快递,则类似.....

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

最新更新