大网数据广告活动
服务器运维问答

Nginx reverse proxy too many redirections

· 52CE 我爱测

I want to configure nginx to act as a reverse proxy that will redirect to two different Kibana hosts depending on the passed URI. / redirect to the standard and /october/ to the october dedicated Kibana. The first part of the con…

问题原文

原帖链接 · Quentin · CC BY-SA 3.0

I want to configure nginx to act as a reverse proxy that will redirect to two different Kibana hosts depending on the passed URI. / redirect to the standard and /october/ to the october dedicated Kibana. The first part of the configuration (/) works well but I got a Too many redirections error when a try to access /october. I tried to comment out the second part (location /october/) and replace localhost by 10.10.0.3 in the first one and I'm redirected to the october platform. So the problem is on this nginx configuration.

server {
    listen                  80;
    server_name             my.domain.io;
    return                  301 https://$server_name;
}

server {
    listen                  443 ;
    ssl                     on;
    ssl_certificate         /etc/letsencrypt/live/my.domain.io/cert.pem;  
    ssl_certificate_key     /etc/letsencrypt/live/my.domain.io/privkey.pem;  
    server_name             my.domain.io; 
    access_log              /var/log/nginx/kibana.access.log;
    error_log               /var/log/nginx/kibana.error.log;

    location / {
            auth_basic              "Restricted";
            auth_basic_user_file    /etc/nginx/conf.d/kibana.htpasswd;


            location / {
                    proxy_pass              http://localhost:5601;
                    proxy_http_version      1.1;
                    proxy_set_header        Upgrade $http_upgrade;
                    proxy_set_header        Connection 'upgrade';
                    proxy_set_header        Host $host;
                    proxy_cache_bypass      $http_upgrade;
            }

            location /october/ {
                    proxy_pass              http://10.10.0.3:5601;
                    proxy_http_version      1.1;
                    proxy_set_header        Upgrade $http_upgrade;
                    proxy_set_header        Connection 'upgrade';
                    proxy_set_header        Host $host;
                    proxy_cache_bypass      $http_upgrade;
            }
    }
}

已采纳解答

原帖链接 · Quentin · CC BY-SA 3.0

Thanks to the previous responses, I found the solution but don't exactly know "how" and "why" it works...

Here is my new configuration :

server {
    listen                  80;
    server_name             my.domain.io;
    return                  301 https://$server_name;
}

server {
    listen                  443 ;
    ssl                     on;
    ssl_certificate         /etc/letsencrypt/live/my.domain.io/cert.pem;
    ssl_certificate_key     /etc/letsencrypt/live/my.domain.io/privkey.pem;
    server_name             my.domain.io;
    access_log              /var/log/nginx/kibana.access.log;
    error_log               /var/log/nginx/kibana.error.log;

    auth_basic              "Restricted";
    auth_basic_user_file    /etc/nginx/conf.d/kibana.htpasswd;

    location / {
            proxy_pass              http://localhost:5601;
            proxy_http_version      1.1;
            proxy_set_header        Upgrade $http_upgrade;
            proxy_set_header        Connection 'upgrade';
            proxy_set_header        Host $host;
            proxy_cache_bypass      $http_upgrade;
    }

    location = /october {
            return 302 /october/;
    }

    location /october/ {
            proxy_pass              http://10.10.0.3:5601/;
            proxy_http_version      1.1;
            proxy_set_header        Upgrade $http_upgrade;
            proxy_set_header        Connection 'upgrade';
            proxy_set_header        Host $host;
            proxy_cache_bypass      $http_upgrade;
    }
}

There is no need for proxy_redirect directive. The trick was to add a / at the end of the /october location and redirect /october to /october/whit 302 code. Don't forget that you have to set server.basePath to "/october"in your kibana.yml file.

This post helped me : How to remove the path with an nginx proxy_pass

Hope this will help...

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-12-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。