django - 在 nginx+uwsgi 中运行时,django url 模式会去除正斜杠
问题描述
对于以下 url 模式:
re_path(r'proxy/(?P<url>.*)', myview)
当我发送proxy/http://www.google.com
myview 函数接收 url 为http:/www.google.com
(使用 single /
)
它发生在 uwsgi+nginx setup ,当使用 runserver url is 运行时http://www.google.com
。
解决方案
这是因为nginx
会自动将 URL 中的双斜杠合并为一个:
http://nginx.org/en/docs/http/ngx_http_core_module.html#merge_slashes
启用或禁用将 URI 中的两个或多个相邻斜杠压缩为单个斜杠。
请注意,压缩对于正确匹配前缀字符串和正则表达式位置至关重要。没有它,“//scripts/one.php”请求将不匹配
你应该在你的禁用它nginx.conf
:
merge_slashes off;
推荐阅读
- excel - 合并单元格vba excel
- kubernetes - k8s书签解决了什么?
- sharepoint - 使用 Power Automate 在 Sharepoint 中安排文件的复制/移动和重命名
- python - SciPy.optimize.least_squares() 5PL 曲线优化问题
- sql - 无法连接到 (localdb)\MSSQLLocalDB - 由于触发器执行
- amazon-web-services - 基于分片的 AWS Kinesis 批处理
- android - 未解决的参考:frame_layout
- javascript - 多个轮播没有以正确的方式实施
- android - 如何在录制的 Android 视频中添加水印
- python - 非零二进制精度,但 Keras 分类器中的精度为 0