node.js - 如何使用 nginx 将 url 参数提供给 proxy_pass?
问题描述
我有一个正在运行的节点前端服务器和正在运行的localhost:3000
快速服务器localhost:5000
在/
我的配置位置
proxy_pass http://localhost:3000; #whatever port your app runs on
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
localhost:5000
当我向我发送请求时(failed)net::ERR_CONNECTION_REFUSED
出现错误,我认为 Nginx 阻止我执行请求
所以我想给出一个/api
位置,将 URL 参数/api/
放在后面并将其放在前面localhost:5000
例如:当我去domain.com/api/admin/news
请求将被发送到localhost:5000/api/admin/news
我正在尝试使用此配置来解决此问题,但无法使其正常工作
location /~* ^/api/(.*){
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_pass http://localhost:5000/$1$is_args$args;
}
任何帮助将不胜感激,谢谢
解决方案
推荐阅读
- mysql - 如何将 IntegerField 迁移到 ForeignKey
- java - JasperReports 不会迭代列表列表的元素
- python-3.x - 读写大文本文件python太慢
- python - Windows 10 python Locust 'locust' 未被识别为 cmdlet、函数的名称
- entity-framework-core - 如果无法读取该项目,是否可以从 Cosmos 中删除该项目?
- java - 释放按钮时停止 ObjectAnimation
- javascript - 每当有重新排序时更新所有行号
- ios - 在不使用设备设置的情况下将应用设置为具有亮/暗模式
- git - 在两个分支之间生成补丁格式
- javascript - 有什么方法可以在消费者超时后自动启动 eventthub 订阅?