ssl - 反向代理时如何阻止Nginx将端口添加到外部URL
问题描述
我在提供Cloudinary url时遇到了Nginx的问题。
我已经设置了一个反向代理,它基本上为我的 localhost 应用程序提供公共服务器并强制使用 https。
我使用 Cloudinary 作为我的图像服务。
问题是由于某种原因 Nginx 将:80添加到我的 Cloudinary url 的主机部分,它会导致 404 错误。
例如,我的所有网址都变为https://res.cloudinary.com:80/ ...
这是我的反向代理配置:
server {
listen 80;
server_name test.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name test.example.com;
ssl on;
ssl_certificate /etc/nginx/ssl/*.example.com/server.crt;
ssl_certificate_key /etc/nginx/ssl/*.example.com/server.key;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
我究竟做错了什么?
解决方案
查看您的nginx
配置,它会将所有请求代理/
到http://localhost:8080
. 我无法从上面的配置片段中看到它将代理到https://res.cloudinary.com:80/。
如果我不得不猜测,它是在您的 localhost 上运行的端口 8080 上的应用程序/服务对此负责。你检查一下是不是这样?
推荐阅读
- c - 如何解决三个头文件之间的循环依赖
- postgresql - Docker:使用参数制作自定义 docker 镜像
- php - 如何在 PHP 中捕获类中的异常?
- javascript - 如何修复 NodeJS 不断向我抛出的“意外令牌 {”错误?
- angular - Firestore/Firebase - 为关注/关注的用户帖子建模数据的方法
- node.js - 如何过滤猫鼬changeStream
- angular - 如何在 Angular 6 的嵌套 formBuilder 中添加新的 formControl?
- inno-setup - 首先卸载旧版本时禁用/跳过 Inno Setup“选择目录”页面
- domain-driven-design - DDD中的上下文映射和限界上下文有什么区别?
- r - 如何使用 mschart for R 更改图例文本?