【问题标题】:Apache2 proxy to spring-boot app, problem with Oauth2Apache2代理到spring-boot应用程序,Oauth2问题
【发布时间】:2019-11-08 11:06:56
【问题描述】:

我在 8080 端口上运行 Tomcat。我有一个 apache2 代理,它有 SSL 证书,它将所有加密流量从 443 传递到 8080 端口。一切正常,除了 facebook 身份验证。

如果 apache2 关闭,并且 SSL 在 tomcat 中打开 - 它正在工作。我相信流量加密的问题,也许 facebook 从我的非 SSL tomcat 服务器检索请求?

我的 apache 配置:

服务器名称 thing-tracker.ga SSL引擎开启 SSLCertificateFile /opt/cert/cert.pem SSLCertificateKeyFile /opt/cert/privkey.pem SSLCertificateChainFile /opt/cert/chain.pem

    DefaultType text/html
    ProxyRequests off
    ProxyPreserveHost On

    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} =websocket
    RewriteRule /(.*)           ws://localhost:8080/$1 [P,L]
    RewriteCond %{HTTP:Upgrade} !=websocket
    RewriteRule /(.*)           http://localhost:8080/$1 [P,L]

   # ProxyPass / http://localhost:8080/
   # ProxyPassReverse / https://localhost/

错误:

由于异常,从请求 [/login/oauth2/code/facebook] 转发到错误页面

[读取 OAuth 2.0 时发生错误错误:JSON 解析错误: 无法从 START_OBJECT 令牌中反序列化 java.lang.String 的实例;

嵌套异常是 com.fasterxml.jackson.databind.exc.MismatchedInputException:无法从 START_OBJECT 令牌中反序列化 java.lang.String 的实例 在 [来源:(sun.net.www.protocol.http.HttpURLConnection$HttpInputStream);行:1,列:10](通过引用链:java.util.LinkedHashMap["error"]);

【问题讨论】:

    标签: facebook spring-boot tomcat oauth-2.0 apache2


    【解决方案1】:

    尝试在 apache 上强制 https:

    RequestHeader set X-Forwarded-Proto https

    在你的 spring boot 属性上添加:

    server.use-forward-headers=true
    server.tomcat.remote_ip_header=x-forwarded-for
    server.tomcat.protocol_header=x-forwarded-proto
    

    我也遇到了同样的问题,但是解决了。

    【讨论】:

    • 谢谢,我已经检查过了,它工作正常!但现在我使用 docker 并使用它进行重定向。
    猜你喜欢
    • 2021-01-07
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    • 2020-09-08
    • 2020-10-19
    • 2020-01-09
    • 2020-08-28
    • 2020-07-13
    相关资源
    最近更新 更多