nginx - nginx proxy_pass 在 url 中重写不保留原始路径
问题描述
我正在尝试设置 nginx 以通过以下方式转发传入请求:
http://localhost/service -> http://localhost:8080
http://localhost/service/foo -> http://localhost:8080/foo
现在我可以使用以下配置实现第一行:
...
upstream service {
server service:8080;
}
...
location /service/ {
server_name_in_redirect off;
proxy_pass http://service;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
但是当我添加额外的路径(例如 /foo)时,url 会以这种方式重写
http://localhost/foo/
因此我永远无法访问 localhost:8080/foo。关于如何使这项工作的任何想法?提前致谢
解决方案
推荐阅读
- android - 带有架构导航组件的底部导航片段的动画
- r - R - f_num,但带逗号
- c++ - 如何在 C++ 中检查模板类中的类型?
- google-cloud-platform - 将 gcloud sql 备份恢复到另一个实例会引发 400 错误
- python - 在纸牌游戏中需要有关此功能的建议
- flutter - 我的 Flutter 网页的滚动正文出现问题
- r - 我将此数据集导入到 RStudio,但它为 NULL
- python - Python:Spacy NER 和内存消耗
- build.gradle - 将 ArchiveName 传递给 gradle 中的 UploadArchives
- python-3.x - InvalidSessionIdException 和 StaleElementReferenceException 错误(Python 3 / Selenium)