http - 带有 http 和 https 的 Nginx 上游

标签 http ssl nginx https reverse-proxy

我有一些关于 nginx 绕过 http 和 https 的问题,在上游 block 中

上游 block :

upstream bypass{
      server 192.168.99.1:80; #http
      server 192.168.99.2:443 backup; #https
}

当http 80有问题(服务器宕机等),我想重定向到https 443,

这个 block 对我不起作用。

位置 block :

location / {
      proxy_pass https://bypass;
      proxy_redirect off;
}

我该如何解决?

最佳答案

这很有效:为不同端口上的每个后端创建服务器配置部分,并在没有 ssl 的情况下在内部转发到两个端口。

在此示例中,您可以看到第一个服务器如何充当具有缓存内容(通过 https 可用)的主服务器,如果缓存内容不可用,则使用第二个服务器(通过 http)。

(使用nginx 1.19.6,仅供引用)

upstream backends {
    server 127.0.0.1:8082;
    server 127.0.0.1:8081 backup;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name example.com;

    # ssl certs etc here

    location / {
        proxy_pass http://backends;
        proxy_next_upstream error timeout http_404 http_403;
    }

    access_log  /var/log/nginx/access.log upstreamlog;
}

server {
    listen 8081;
    location / {
        add_header X-Cache MISS;
        proxy_pass http://server1;
        proxy_set_header Host server1;
    }
}


server {
    listen 8082;
    location / {
        add_header X-Cache HIT;
        proxy_pass https://server2;
        proxy_set_header Host server2;
    }
}

关于http - 带有 http 和 https 的 Nginx 上游,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29071168/

相关文章:

c# - 如何在异步多线程爬虫中锁定回调类?

node.js - Express 在浏览器中返回 200,但使用 curl -I 返回 404

image - 如何编码图像以通过 Python HTTP 服务器发送?

Android 上传前调整图像大小(重新采样/缩小采样)

SSL (https) 拒绝在 IPv6 网络 Digitalocean 中加载网站

linux - CentOS/Nginx 服务器无法运行,正在托管 Node 应用程序

ssl - Nginx certbot SSL 不适用于 Cloudflare

python - 带有 flask 和 memcached 的 nginx 返回一些乱码

silverlight - Azure 和 SSL 在暂存中不起作用

ssl - Nginx SSL 证书路径格式