cloudreve 配置 onlyoffice 的 wopi 并通过 nginx 代理 https 遇到请求自动变成 http 的问题解决

将 onlyoffice 相关的 nginx 配置 server 块前添加

        upstream docservice {
          server office.ucoder.top【前面这个位置填onlyoffice服务地址】;
        }

        map $http_host $this_host {
            "" $host;
            default $http_host;
        }

        map $http_x_forwarded_proto $the_scheme {
             default $http_x_forwarded_proto;
             "" $scheme;
        }

        map $http_x_forwarded_host $the_host {
            default $http_x_forwarded_host;
            "" $this_host;
        }

        map $http_upgrade $proxy_connection {
          default upgrade;
          "" close;
        }

然后再 location 的代理块中添加

        add_header X-Content-Type-Options nosniff;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $proxy_connection;
        proxy_set_header X-Forwarded-Host $the_host;
        proxy_set_header X-Forwarded-Proto $the_scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

我的完整配置如下:

upstream docservice {
  server office.ucoder.top;
}

map $http_host $this_host {
    "" $host;
    default $http_host;
}

map $http_x_forwarded_proto $the_scheme {
     default $http_x_forwarded_proto;
     "" $scheme;
}

map $http_x_forwarded_host $the_host {
    default $http_x_forwarded_host;
    "" $this_host;
}

map $http_upgrade $proxy_connection {
  default upgrade;
  "" close;
}
server{
    listen 443 ssl ;
    server_name office.ucoder.top;
    ssl_certificate /etc/letsencrypt/live/blog.ucoder.top/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/blog.ucoder.top/privkey.pem; # managed by Certbot

    location / {
        proxy_pass http://ucoder.top:10013;
        proxy_http_version 1.1;
            proxy_read_timeout   3600s;
        add_header X-Content-Type-Options nosniff;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $proxy_connection;
        proxy_set_header X-Forwarded-Host $the_host;
        proxy_set_header X-Forwarded-Proto $the_scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size 5000m;
    }

}
server{
    if ($host = office.ucoder.top) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80 ;
    server_name office.ucoder.top;
    return  301 https://$server_name$request_uri;


}

添加新评论

6 + 9 =