0

私たちが持っているもの:

  • Apache nginx の束。
  • フォーラム Tinyboard。

Apache による認証は正常に進行していますが、関数 mkhash として nginx を使用しています。

    function mkhash($username, $password, $salt = false) {
    global $config;

    if (! $salt) {
    // Create some sort of salt for the hash
     $salt = substr(base64_encode(sha1(rand(). time(), true). $config['cookies']['salt']), 0 , 15) ;

     $generated_salt = true;
    }

     // Generate hash (method is not important as long as it's strong)
     $hash = substr(base64_encode(md5($username . $config['cookies']['salt']. sha1($username . $password . $salt . ($config['mod']['lock_ip']? $_SERVER['REMOTE_ADDR']:''), true), true)), 0 , 20);

    if (isset($generated_salt))
     return array($hash, $salt);
    else
     return $hash;
    }

は正しい値を返さず、承認は失敗します。検証は次のとおりです。

    if ($cookie[ 1 ]! == mkhash($cookie[0], $user['password'], $cookie[2] ) {
     // Malformed cookies
     destroyCookies();
     mod_login();
     exit;
    }

ログインを成功させるには、条件を実行しないでください。

nginx 経由で返される値の例 (ログイン失敗):

  • cookie0: 管理者
  • cookie1: Ib37H5U7hCi6Br9M09V
  • cookie2: Nn2wUxlnirvgzkn
  • mkash: fN1jv3t9ccThde0Kp30h

Apache 経由で返される値の例 (ログイン成功):

  • cookie0: 管理者
  • cookie1: SgaMoQ07upLoz9Q7Wdz6
  • cookie2: Zp6BQ2b20Jsh 1R
  • mkhash: SgaMoQ07upLoz9Q7Wdz6

ポート 82 でハングする Apache (そのポートで適切に処理された場合、認証は成功します)。Nginx 自体は静的ファイルのみを取得し、動的コンテンツは Apache から取得します。その理由は何でしょうか?

    location / {
        proxy_pass http://backend;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_connect_timeout 120;
        proxy_send_timeout 120;
        proxy_read_timeout 180;
    }
4

1 に答える 1

3

ハッシュ生成では、$_SERVER['REMOTE_ADDR']

これは常に 127.0.0.1 に設定されます。

同じ IP アドレスを取得するには、これを に変更する必要があり$_SERVER['HTTP_X_REAL_IP']ます (X-Real-IP は、nginx.conf で定義したものです)。

于 2013-11-03T13:06:26.470 に答える