首页 > 解决方案 > 反向代理时如何阻止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;
    }
}

我究竟做错了什么?

标签: sslnginxcdncloudinary

解决方案


查看您的nginx配置,它会将所有请求代理/http://localhost:8080. 我无法从上面的配置片段中看到它将代理到https://res.cloudinary.com:80/

如果我不得不猜测,它是在您的 localhost 上运行的端口 8080 上的应用程序/服务对此负责。你检查一下是不是这样?


推荐阅读