node.js - Apache2 上的代理错误 502,用于反向代理到 Digital Ocean 上的 NodeJs 子域应用程序
问题描述
大家好
我试图在 Digital Ocean 上部署我的 nodejs api,在子域https://api.host.com下。它有一些路径波纹管,都从 /v0.1 开始。
在这个 droplet 上,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 服务器将请求从子域通过代理转发到侦听端口 8080 的 nodeJS 应用程序做同样的事情。
我相信您只需要将根代理传递给 localhost:3000 并且 nodeJS 应用程序应该处理路由。
例如,如果您使用的是 express,则类似于.....
app.get('/v.01/users/', function (req, res) {
res.sendFile('/v.01/users/index.html'); });
推荐阅读
- c++ - 具有多个默认构造函数的普通类的示例?
- sql - 如何正确设置查询以在 SQL 中获取特定结果
- azure - Azure Web App + Unity3d WebGl 错误:我们需要在 Module['wasmBinary'] 上预加载和设置 wasm 二进制文件
- laravel - Laravel 单元测试非法偏移类型
- html - 使用 CSS,有没有办法当我将鼠标悬停在一个组件上时,另一个组件变得可见?
- c# - 添加为邮件附件时文件似乎已损坏
- git - 一个用于 Android+web 服务的 git repo
- node.js - 为 FireFox 设置安全 cookie 失败,但适用于 Chrome。如何为 FireFox 设置安全 cookie?
- active-directory - 具有本地 AD Windows 身份验证和远程 3rd 方 WebApi 的 WPF 架构?
- c# - 如何在 HTML 标题标签中从右到左排列由英语和波斯语单词组合而成的文本