facebook - Apache2 proxy to spring-boot app, problem with Oauth2
问题描述
I'm running the Tomcat on 8080 port. I have an apache2 proxy, it has SSL certificates, and it passes all encrypted traffic from 443 to 8080 port. All works fine, except facebook authentication.
If apache2 turned off, and SSL is on in tomcat - it is working. I believe the problem in traffic encryption, maybe the facebook retrieves the request from my not SSL tomcat server?
My apache config:
ServerName thing-tracker.ga SSLEngine On 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/
The error:
Forwarding to error page from request [/login/oauth2/code/facebook] due to exception
[An error occurred reading the OAuth 2.0 Error: JSON parse error:
Cannot deserialize instance of java.lang.String
out of START_OBJECT token;
nested exception is
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.lang.String
out of START_OBJECT token
at [Source: (sun.net.www.protocol.http.HttpURLConnection$HttpInputStream); line: 1, column: 10] (through reference chain: java.util.LinkedHashMap["error"]);
解决方案
尝试在 apache 上强制 https:
RequestHeader set X-Forwarded-Proto https
并在您的弹簧启动属性上添加:
server.use-forward-headers=true
server.tomcat.remote_ip_header=x-forwarded-for
server.tomcat.protocol_header=x-forwarded-proto
我遇到了同样的问题,但这解决了。
推荐阅读
- python - AttributeError:“list”对象没有属性“send_keys”
- javascript - 使用 Slick carousel 对可见项目进行编号
- java - 如何对 Selenium 中的 WebElement 列表执行操作
- c# - 我应该调用异步 SignalR 集线器方法 MethodNameAsync(),还是不调用
- python - 如果我使用 Cloud Foundry 和 python buildpack,如何安装 ffmpeg
- mysql - SELECT 查询,其中 LIMIT 是重复键的不同计数
- elasticsearch - 我想用我自己的证书替换搜索保护演示证书
- javascript - 在 axios 的标头中发送令牌时获取 500 错误代码和跨源
- java - 转换为二进制 Java 类时的 Jasmin NoSuchMethodError
- xml - 当我尝试将 xsd 附加到 xml 时,xml 的根变为红色(在 Intellij IDEA 中),这可能是什么问题?