4

私はnginxに本当に慣れていないので、auth_requestに問題があります。

次のconfで

server {
    listen 80;
    listen [::]:80;

    root /var/www/html;

    index index.php;
    server_name www.test.com;

    error_page 401 403 = @error401;

    location @error401 {
        return 302 http://login.test.com;
    }

    auth_request /auth;

    location = /auth {
        internal;
        proxy_pass http://auth.test.com;

        proxy_pass_request_body off;

        proxy_set_header Content-Length "";
        proxy_set_header X-Original-URI $request_uri;
        proxy_set_header Host $http_host;

        if ($http_cookie ~* "sso_token=([^;]+)(?:;|$)") {
            set $token "$1";
        }
        proxy_set_header X-SSO-TOKEN $token;
    }

    location / {
        try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;

        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

http://www.test.comにアクセスすると、 500http ステータス コードが表示されます。

そしてエラーログに

auth request unexpected status: 302 while sending to client, client: 172.16.8.23, server: www.test.com, request: "GET / HTTP/1.1", host: "www.test.com"

現時点では、http://auth.test.com401はif X-SSO-TOKENis missing と200if it is thereを返すだけです。を返しません302

proxy_passそれをたどって最後のステータスコードを返すのではなく、それ自体がモジュールに戻っている302と思いauth_requestます(それが理にかなっている場合)

これらのドキュメントhttp://nginx.org/en/docs/http/ngx_http_auth_request_module.htmlを見ると、これは機能するはずですが、わかりません。

ヘルプやポインタをいただければ幸いです。

ありがとう

4

1 に答える 1