配置Apache反向代理转发Firebase认证请求遇404问题求助
Firebase反向代理配置排查请求
尝试配置反向代理将认证请求转发至firebaseapp.com,实现Google和Apple的signInWithRedirect登录,但配置后无任何反应,访问https://example.com/__/auth/handler时出现404错误,以下是当前配置详情及排查建议:
当前配置详情
1. Google Cloud授权重定向URI
https://example.com/__/auth/handler
2. Apache虚拟主机配置(已重启服务器)
# HTTP Configuration <VirtualHost *:80> ServerName example.com Redirect permanent / https://www.example.com </VirtualHost> # HTTPS Configuration <VirtualHost *:443> ServerName example.com ServerAlias www.example.com DocumentRoot /home/example/public_html SSLEngine on SSLCertificateFile /var/cpanel/ssl/apache_tls/example.com/certificates SSLCertificateKeyFile /var/cpanel/ssl/apache_tls/example.com/combined ProxyPreserveHost On ProxyPass /__/auth/ https://example-b54e1.firebaseapp.com/__/auth/ ProxyPassReverse /__/auth/ https://example-b54e1.firebaseapp.com/__/auth/ </VirtualHost>
3. Firebase客户端配置
const firebaseConfig = { apiKey: "{API_Key}", authDomain: "example.com", projectId: "example-b54e1", storageBucket: "example-b54e1.appspot.com", messagingSenderId: "{number}", appId: "{number}", };
可能的问题及排查方向
- 重定向URI与域名跳转冲突:HTTP配置将
example.com永久重定向到www.example.com,但Google Cloud仅配置了无www域名的重定向URI,需补充添加https://www.example.com/__/auth/handler到授权列表。 - Apache代理模块未启用:反向代理依赖
mod_proxy和mod_proxy_http模块,执行apachectl -M查看是否加载,未加载则需在Apache配置中添加对应LoadModule指令后重启服务器。 - ProxyPass路径匹配错误:当前规则末尾带斜杠
/__/auth/,可能导致/__/auth/handler路径解析异常,尝试调整为ProxyPass /__/auth https://example-b54e1.firebaseapp.com/__/auth(去掉末尾斜杠)。 - Firebase授权域名未配置:需在Firebase控制台→Authentication→设置→授权域中,添加
example.com和www.example.com两个域名。 - 主机头与SSL证书问题:确认
ProxyPreserveHost On正确传递了主机头,同时检查SSL证书是否完整有效,避免代理请求因证书验证失败被拦截。
内容的提问来源于stack exchange,提问作者kelsheikh
相关产品推荐
相关产品推荐

