【问题标题】:github oauth and nginx proxygithub oauth 和 nginx 代理
【发布时间】:2014-04-24 21:03:57
【问题描述】:

我觉得我已经搜索了整个互联网并尝试了几乎所有方法来解决我的问题。现在我决定问问你,希望有人能帮助我。

我有一个在 sub2.domain.tld:3000 上运行的节点应用程序。现在我想用 nginx 将此应用程序代理到端口 80,以便我能够使用 sub.domain.tld 访问应用程序。但这不是问题。我能够到达第一个站点。

问题出现在带有OAuth-API 的身份验证例程之后,以验证应用程序的用户。

当浏览到 sub2.domain.tld:3000 时,该过程运行良好。但是,当我更改配置中的 url 并尝试浏览 sub.domain.tld 时,身份验证过程会遇到错误(error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL .... .).

所以我想我在使用 nginx 重定向 url 时犯了一个错误。

我使用的是 nginx 1.4.7 和节点 0.10.26

我的 nginx 配置文件是这样的:

server {
    listen      80;
    access_log /var/log/nginx/access_log_sub;
    server_name sub.domain.tld;

    location / {
        include proxy_params;
        proxy_pass http://IP:3000;
        proxy_set_header    Host            $http_host;
        proxy_set_header    X-Real-IP       $remote_addr;
        proxy_set_header    Client-IP       $remote_addr;
        proxy_set_header    X-Forwarded-for $remote_addr;
    }
}

但我相信 OAuth 正在验证 sub2.domain.tld:3000 并且它与 sub.domain.tld 发生冲突

希望你能帮我解决这个问题。

【问题讨论】:

    标签: nginx oauth proxy


    【解决方案1】:

    错误不是来自 nginx,而是来自您的 OAuth 提供者:

    redirect_uri 参数是可选的。如果省略,GitHub 会将用户重定向到 OAuth 应用程序设置中配置的回调 URL。如果提供,重定向 URL 的主机和端口必须与回调 URL 完全匹配。重定向 URL 的路径必须引用回调 URL 的子目录。

    -- https://developer.github.com/v3/oauth/#redirect-urls

    【讨论】:

    • 太棒了,从配置更改redirectURL,一切正常,谢谢你
    【解决方案2】:

    这是一个老问题,但是...

    尝试将您的主机标头更改为

    proxy_set_header Host $host:$server_port
    

    这可能会也可能不会,具体取决于您的应用程序。

    顺便说一句,X-Forwarded-For 应该包含一个以逗号分隔的原始客户端及其通过的代理的列表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-04
      • 2016-03-24
      • 2010-11-12
      • 2018-04-24
      相关资源
      最近更新 更多